- 论坛徽章:
- 0
|
我用jsp读取一文本文件,然后替换里面指定的字符,在生成一个新的文本文件,在windows系统正常,在redhat linux as 3.0 下出现乱码!
文本文件 test.html 的内容只有一句话: 这里是日本的地方。
我用jsp读取后,替换掉里面的日本后生成一个新的 test1.html 文件.
jsp代码如下:
<%@ page contentType="text/html; charset=GBK" %>;
<%@ page language="java" %>;
<%@ page import="java.io.*"%>;
<%
String webroot=config.getServletContext().getRealPath("/" ;
String replace="中国";
String Str="",temp="";
try {
FileReader fr =new FileReader(webroot+"test.html" ;
BufferedReader bfr= new BufferedReader(fr);
while((temp=bfr.readLine())!=null){
Str+=temp+"\r\n";
}
fr.close();
Str=Str.replaceAll("日本",replace);
FileWriter fw =new FileWriter(webroot+"test1.html" ;
BufferedWriter bfw= new BufferedWriter(fw);
bfw.write(Str);
bfw.flush();
fw.close();
}catch (Exception e){
out.print(e.toString());
}
out.print("<br>;"+Str);
%>;
我也试图转码了.
我在 Str=Str.replaceAll("日本",replace); 这句的后面分别加了下面的其中一句,但在linux下还是都是乱吗,而在windows下也都变成乱吗了,怎么办????
Str = new String(Str.getBytes("ISO8859_1" ,"GBK" ;
Str = new String(Str.getBytes("ISO-8859-1" ,"GBK" ;
Str = new String(Str.getBytes("GBK" ,"ISO-8859-1" ;
Str = new String(Str.getBytes("GBK" ,"ISO8859_1"); |
|