The so-called input stream is to read the data in the file
Similarly, the character input stream InputStreamReader
4 Construction methods, but 2 are more commonly used:
Construction Method:
A:inputstreamreader (InputStream is): reads data with default encoding
B:inputstreamreader (InputStream is,string charsetname): reads data with the specified encoding
A:inputstreamreader (InputStream is): reads data with default encoding
InputStreamReader ISR = new InputStreamReader (New FileInputStream ("A.txt"));
B:inputstreamreader (InputStream is,string charsetname): reads data with the specified encoding
1 New InputStreamReader (new fileinputstream (2 "Osw.txt"), "UTF-8");
Methods of InputStreamReader:
A * int read (): reads one character at a time
b* int Read (char[] CHS): reads one character array at a time
A * int read (): reads one character at a time
1 int ch = 0; 2 while (ch = isr.read ())! =-1) {3 System.out.print ((char) ch); 4 }56 // release Resources 7 isr.close ();
b* int Read (char[] CHS): reads one character array at a time
1 Char[] CHS =New Char[1024];2 intLen = 0;3 while(len = Isr.read (CHS))! =-1) {4System.out.print (NewString (CHS, 0, Len));5 }6 7 //Freeing Resources8Isr.close ();
Java 21-3 character input stream