inputstreamreader reading Data
█
InputStreamReader Read Data method
? public int read (); Reads a single character. ? public int Read (char[] cbuf); Reads a character into an array. ? public int Read (char[] cbuf,int off, int len); Reads a character into a part of the array.
public static void Main (string[] args) throws IOException { FileInputStream fis = new FileInputStream ("1.txt"); InputStreamReader ISR = new InputStreamReader (FIS);//Does not specify the encoding format, the default system code (UTF-8); //Method One:/* int ch;//while ((ch = (char) isr.read ())! =-1) { //Here cannot be forcibly converted to char here, converted to Char will never equal to-1While ((ch = isr.read ())! =-1) {System.out.print ((char) ch); } */ //Method two:/* char[] Charray = new CHAR[10];int leng = Isr.read (Charray);System.out.println (Charray); * * |
//Method Three: / * char[] charray2 = new CHAR[10]; int leng2 = Isr.read (Charray2, 0,charray2.length); System.out.println (charray2); * * char[] charray2 = new CHAR[10]; int Leng; While ((Leng = Isr.read (charray2,0,charray2.length))! =-1) { //system.out.print (charray2); //cannot directly output the array, because the last read into the array length of the data, will cause the output of the last read into the array String charray2str = new string (Charray2,0,leng); System.out.print (CHARRAY2STR); } fis.close (); isr.close (); } } |
Java--io class, character stream reading data