IO问题

lazy1102 2014-03-11 05:03:39
import java.io.*;
public class TestFileInputStream {

public static void main(String[] args) {
try {
FileInputStream fis=new FileInputStream("D:/a/b/chongfu.txt");
FileOutputStream fos=new FileOutputStream("d:/a/b/chongfu3.txt");
int c=0;
while((c=fis.read())!=-1){
fos.write((char)c);
System.out.print((char)c);
}
fis.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("程序异常");
}


}

}
我不懂得是:打印到控制台的汉字是乱码,我也知道为什么是乱码,但是为什么打印到d:/a/b/chongfu3.txt文件中,汉字却没有乱码
...全文
138 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
乔不思 2014-03-12
  • 打赏
  • 举报
回复
txt好像编码的方式是 utf-8,你这里在控制台输出的是 你主机的编码方式,中国范围内是 GBK....
sunbo624 2014-03-12
  • 打赏
  • 举报
回复
哥 你按字符读的 肯定乱啊
gaofuqi 2014-03-11
  • 打赏
  • 举报
回复
windows下默认编码是GBK的,你看一下你项目的编码是不是其他编码?
haha_321 2014-03-11
  • 打赏
  • 举报
回复
就是编码的问题,每个地方的默认编码不同造成的。
msj100ff 2014-03-11
  • 打赏
  • 举报
回复
两个文本文件默认编码相同不会乱码,但是与eclipse环境编码不一致导致乱码

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧