讀取中文
字節流讀取中文的問題:
字節流在讀中文的時候有可能會讀到半個中文,造成亂碼
解決辦法:
1.使用字符流
2.字節流直接操作字符,寫出中文必須將字符串換成字節數組
package io;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Chinese {
public static void main(String[] args) throws IOException {
OutputStream os = new FileOutputStream("chinese.txt");
os.write("你好啊!".getBytes());
os.close();
}
}
寫出回車換行write("\r\n".getBytes())