The InputStreamReader class can convert the InputStream byte stream into a stream of reader characters:
1 voidInputStreamReader () {2 //InputStreamReader class can convert InputStream byte stream into reader character stream3 //no garbled characters in Chinese4File File =NewFile ("E:\\test.txt");5InputStream InputStream =NULL;6InputStreamReader ISR =NULL;7 Char[] ch =New Char[24];8 intLen;9StringBuilder SB =NewStringBuilder ();Ten Try { OneInputStream =Newfileinputstream (file); AISR =NewInputStreamReader (inputstream); - while(len = isr.read (ch))! =-1) { - sb.append (CH); the } - System.out.println (SB); - //get file Encoding format - System.out.println (isr.getencoding ()); +}Catch(FileNotFoundException e) { - //TODO auto-generated Catch block + e.printstacktrace (); A}Catch(IOException e) { at //TODO auto-generated Catch block - e.printstacktrace (); -}finally { - if(ISR! =NULL) { - Try { - isr.close (); in}Catch(IOException e) { - //TODO auto-generated Catch block to e.printstacktrace (); + } - } the } *}
IO: Byte stream conversion character stream