为什么writer规定了utf-8但是写出来还是乱码呢?
代码如下
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream("demo/nihao.dat"),"utf-8"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("demo/nihao2.dat"),"utf-8"));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
bw.write(line);
bw.newLine();
bw.flush();
}
br.close();
bw.close();
}
这样在终端打出来的是对的,但是写出来的文件nihao2.dat里面中文是乱码。