免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2298 | 回复: 0
打印 上一主题 下一主题

读写文本文件时,在windows系统正常,在linux下出现乱码! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-17 10:18 |只看该作者 |倒序浏览
我用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");
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP