Java中用数据流读记事本中的数字显示不正常
来源:百度知道 编辑:UC知道 时间:2024/06/07 16:34:25
真是不好意思忘说了,规定用数据流或对象流
你一定是从字节流转成字符流的时候没有写字符集,所以才会成了乱码。
像下面那样指定字符集为"unicode"就没有问题了。
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\a.txt"), "unicode"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
给你写个方法,你用下吧。
public void readFile(String filename){
BufferedReader in = null;
String s = null;
try {
in = new BufferedReader(new FileReader(filename));
while ((s = in.readLine()) != null) {
System.out.println(s);
}
}
in.close();
} catch (Exception e) {
System.out.println("打开失败!");
}
}
串行化?
那个怎么能用来