今天复习java基础知识时候遇到个问题。我用流存的时候是UTF-8,但是使用FileReader
读的时候,竟然不乱码。。为什么呢?难道FileReader不是GBK格式吗?
public static void main(String[] args) throws Exception {
//writFile();
readFile();
}
public static void readFile()throws Exception{
FileReader fileReader = new FileReader("F:/a.txt");
int len=0;
while ((len=fileReader.read())!=-1) {
System.out.println((char)len);
}
fileReader.close();
}
public static void writFile()throws Exception{
FileOutputStream fileOutputStream = new FileOutputStream("F:/a.txt");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream,"utf-8");
outputStreamWriter.write("您好ass");
outputStreamWriter.close();
}