The read () method of the InputStream class is to take a byte out of the stream, his function prototype is  int read () , and the Read () method of the reader class is to remove a character (a char) from the stream. His function prototype is also  int read (); .
We all know that Java is using the Unicode character set, in Java characters and strings are used UTF-16BE encoding, that is, a character of two bytes, in memory high in low-byte, this is the origin of be, big endian can be understood as large in the beginning, For example, the value of a char is 0XAC56, then in memory form is AC 56, assuming that the memory address of 0XAC is 1, then 0x56 memory address is 2.
The next analysis of reader and inputstream two classes of read () are what the separate, the InputStream class read () method is simply to remove a byte from the input stream, and then return his value,reader class read () The method is to first determine what kind of encoding the input stream uses (in fact, if we do not specify the encoding, then directly using the system's default encoding as the input stream encoding, in the Chinese Windows system by default is GB2312), and then encoded with the input stream to decode a character (the encoding of the input stream determines the number of bytes required to read a character), takes out a character and then encodes the character with UTF-16BE and returns the encoded value , which is the value returned by the Read () method.
here is a small program to prove the above conclusion:
1. First of all, the same sentence week Xuan nature to be generous, said Lin Dai repeatedly nodded, yin-man Zhou Xuan is Hongfu, and only he can marry Tao Yun. saved in UTF-8 and utf-16be two ways, and opened with the 16 Binary editor View:
The read () method of the 2.Reader class reads TXT encoded in UTF-8:
1 ImportJava.io.*;2 classa {3      Public Static voidMain (string[] s)throwsIOException {4 5System.out.println (Read () method reading of the reader Class));6FileInputStream FIS =NewFileInputStream ("Test. txt");7InputStreamReader ISR =NewInputStreamReader (FIS, "UTF-8");8         //System.out.println (isr.getencoding ());9         intCH = 0;Ten         int[] temp =New int[1024]; One         inti = 0; A  -          while(ch = isr.read ())! =-1) { -temp[i++] =ch; theSystem.out.print ((Char) ch); -         } -System.out.print ("\ n")); -  +SYSTEM.OUT.PRINTLN ("encoded value per character:")); -          for(intj = 0; J < I; J + +) { +             if(j% 8 = = 0 && J! = 0) { ASystem.out.print ("\ n"); at             } -System.out.printf ("%04x", Temp[j]); -  -         } -  -     } in}
The output results are as follows:
Reader Class Read () method reads Zhou Xuan nature to be generous vindicate, say Lin Dai repeatedly nod, yin husband Zhou Xuan is hongfu person, also only he can marry Tao Yun. Encoded values per character:5468 5ba3 81EA 7136 8981 6177 61688868 67975934 ff0c 8d24 5a7f 5468 4e5f  6709 4ed6 624D 80FD 5a36 9053 85743002 000D
You can see that each char read by the reader class is saved by UTF-16BE encoding.
Next, read the UTF-8 encoded TXT using the Read () method of the InputStream class:
1 ImportJava.io.*;2 classB {3      Public Static voidMain (string[] s)throwsIOException {4System.out.println ("read () method of the InputStream class reads");5         intCh0 = 0, x = 0;6FileInputStream FIS =NewFileInputStream ("Test. txt");7          while((Ch0 = Fis.read ())! =-1) {8             if(x + +% = 0 && x! = 0) {9System.out.print ("\ n");Ten             } OneSystem.out.printf ("%02x", ch0); A         } -System.out.print ("\ n")); -     } the}
The output results are as follows:
E5 AE A3 E8 A8 AA E7 9E B6 E8 A6 bayi E6B7 E6, A8 E8 A1 A8 E7, BD E4 B8 3>-A8 E5 AE A3 E6 98-E4 BB-E6 8D E8 E8 B4 E3 0D
The difference between reader and read () in InputStream two classes