1. Bufferedinputstream reading data
Bufferedinputstream construction method, as follows:
Construction Method Summary |
BufferedInputStream(InputStream in) Create one BufferedInputStream and save its arguments, that is, the input stream for in future use. |
BufferedInputStream(InputStream in, int size) creates a specified buffer size BufferedInputStream and saves its arguments, that is, the input stream for in future use. |
2. code example:
1 Packagecn.itcast_05;2 3 ImportJava.io.BufferedInputStream;4 ImportJava.io.FileInputStream;5 Importjava.io.IOException;6 7 /*8 * Note: Although we have two ways to read, note that both of these methods can only be used in one code for the same object. 9 */Ten Public classBufferedinputstreamdemo { One Public Static voidMain (string[] args)throwsIOException { A //Bufferedinputstream (InputStream in) -Bufferedinputstream bis =NewBufferedinputstream (NewFileInputStream ( -"Bos.txt")); the - //reading Data - //int by = 0; - //While (by = Bis.read ())! =-1) { + //System.out.print ((char) by); - // } + //System.out.println ("---------"); A at byte[] Bys =New byte[1024]; - intLen = 0; - while(len = Bis.read (bys))! =-1) { -System.out.print (NewString (bys, 0, Len)); - } - in //Freeing Resources - bis.close (); to } +}
Run the effect as follows:
Java Fundamentals Hardening IO Stream Note 29:bufferedoutputstream/bufferedinputstream (byte buffer stream) Bufferedinputstream read data