java 用readline()读取带有汉字的文本文档,怎样才能做到不乱码

如题所述

这个要根据文档的编码来处理,可以用read(bytes); new String(bytes, "gbk"); // 或其它编码ucs2,utf8之类的。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-06
用FileReader..read()方法 一次读取1个字符
第2个回答  推荐于2018-04-11
文件读写乱码问题

读文件:
InputStreamReader isr = new InputStreamReader(new FileInputStream(
filePath), charsetName);

写文件:
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(
filePath), charsetName);本回答被网友采纳
第3个回答  推荐于2016-02-21
照我的代码写就可以了。
import java.io.FileReader;

public class reader {

public static void main(String args[]) throws Exception{

FileReader a=new FileReader("1.txt");

int c;

while((c=a.read())!=-1){

System.out.print((char)c);
}

a.close();

}
}本回答被提问者采纳
相似回答