預設使用的就是gbk編碼,這裡的例子改成了utf8編碼寫入—編碼 讀取—解碼 字元流 = 位元組流 + 編碼表#####################快捷操作的類FileWriter and FileReader ...
預設使用的就是gbk編碼,這裡的例子改成了utf8編碼
寫入—編碼
private static void writeText() throws IOException { FileOutputStream fos = new FileOutputStream("utf8.txt"); OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8"); osw.write("求"); osw.close(); }
讀取—解碼
private static void readCNText() throws IOException { FileInputStream fis = new FileInputStream("utf8.txt"); InputStreamReader isr = new InputStreamReader(fis,"UTF-8"); int i = 0; while((i = isr.read())!=-1){ System.out.println((char)i); } isr.close(); }
字元流 = 位元組流 + 編碼表
#####################快捷操作的類
FileWriter and FileReader