The default is gbk encoding, the example here is changed to utf8 encoding
write-encoding
private static void writeText() throws IOException { FileOutputStream fos = new FileOutputStream("utf8.txt"); OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8"); osw.write("求"); osw.close (); }
read-decode
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(); }
Character stream = byte stream + encoding table
##################### Shortcut class
FileWriter and FileReader