String path = CmsContext.projectPath;
String realPath = path + "/index.html";
File file = new File(realPath);
/* DEL */
//System.out.println("#####:"+ realPath);
if(file.exists() || file.isDirectory()){
System.out.println("首页面可编辑... ");
/** 将html内容读取出来 */
try {
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(file));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
in.close();
/* DEL */
//String clob = new String(out.toString().getBytes("iso8859-1"),"GB2312");
String encod_char = out.toString();
如何将读出来的字符串的编码 正常显示,现在是乱码, index.html 格式是 UTF-8 的 但是直接这么读出来是乱码的.
求帮助 ...
解决方案 »
- js的random()生成的两个随机数会不会一样
- myeclipse怎样从数据库生成一对一实体关系
- struts2 spring hibernate 页面跳转后 form表单数据清除问题
- 上传文件时抛出 java.io.FileNotFoundException (拒绝访问。)
- struts2、spring2、hibernate3整合问题
- 关于提交验证(struts)
- 请问JSF和Struts有什么区别
- 开发EJB需要安装什么软件?
- Eclipse + sqlserver 连接问题
- 说说你所在公司用的是hibernate还是mybatis,看看哪个受欢迎些
- 急,在线等!调用ajax,返回json,报异常java.lang.OutOfMemoryError: Java heap space
- ejb3.0 rmi调用失败??
Test.java代码:/**
*
*/
package encodingTest;/**
* @author wkupaochuan
* @time Apr 11, 2012
* @version V 1.0
*/import java.io.*;
public class Test {
public static void main (String agrs[]) throws IOException
{
File f = new File("C://1.html");
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(f));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
in.close();
String encod_char = out.toString();
System.out.println(encod_char);
}}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<head>实验</head>
<body>
主题
</body>
</html>