1. Overview of Bufferedoutputstream/bufferedinputstream (byte buffer stream)
It is really much faster to define an array than it was to read one byte at a time, so it seems that a buffer is still very good. Since this is the case, then, when Java began to design, it also took into account this problem, it is specifically provided with a buffer byte class. This class is called: Buffer Class (High efficiency Class)
Write Data : Bufferedoutputstream
Read Data : Bufferedinputstream
The construction method can specify the size of the buffer, but we generally do not use it because the default buffer size is sufficient .
2. Bufferedoutputstream Construction method :
BufferedOutputStream(OutputStream out) creates a new buffered output stream to write data to the specified underlying output stream. |
BufferedOutputStream(OutputStream out, int size) creates a new buffered output stream that writes data with the specified buffer size to the specified underlying output stream. |
Bufferedoutputstream construction method, Why not pass a specific file or file path, but pass a OutputStream object?
A: The reason is simple, the byte buffer stream only provides buffers, designed for efficiency. However, the actual read and write operation is also dependent on the basic flow object implementation.
3. Bufferedoutputstream Write Data , code example:
1 Packagecn.itcast_05;2 3 ImportJava.io.BufferedOutputStream;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 7 Public classBufferedoutputstreamdemo {8 Public Static voidMain (string[] args)throwsIOException {9 //Bufferedoutputstream (OutputStream out)Ten //FileOutputStream fos = new FileOutputStream ("Bos.txt"); One //bufferedoutputstream bos = new Bufferedoutputstream (FOS); A //Simple notation -Bufferedoutputstream BOS =NewBufferedoutputstream ( - NewFileOutputStream ("Bos.txt")); the - //Write Data -Bos.write ("Hello". GetBytes ()); - + //Freeing Resources - bos.close (); + } A}
Java Fundamentals Hardening IO Stream Note 28:bufferedoutputstream/bufferedinputstream (byte buffer stream) Bufferedoutputstream write data