Buffer stream of java IO stream (reprinted), javaio
Java buffer streams do not provide IO functions. They only increase efficiency by adding buffering to other streams, such as packaging other streams. When files or other targets are frequently read or written, the efficiency is low and the efficiency is poor. In this case, the buffer stream can be used to read and write information more efficiently. Because the buffer stream first caches the data and then writes or reads it together. Therefore, the buffer stream is very important. When I/O operations are performed, remember to add the buffer stream to improve performance.
Buffer streams are divided into byte and Character Buffer streams byte buffer streams: BufferedInputStream-byte input buffer stream BufferedOutputStream-byte output buffer stream Character Buffer streams: bufferedReader-character input buffer stream BufferedWriter-character output buffer stream The following describes the use of these four buffer streams.
I. byte buffer stream 1. bufferedOutputStream-bytes output buffer stream BufferedOutputStream class implements the buffer output. By setting this output stream, the application can write each byte to the underlying output stream, instead of calling the underlying system for writing every byte. Sample Code: 2. BufferedInputStream-buffer stream for byte input BufferedInputStream to add a buffer function for other input streams. An internal buffer array is created when BufferedInputStream is created to buffer data and improve performance. Sample Code:
Ii. Character Buffer stream 1. BufferedWriter-character output buffer stream writes text to the character output stream, buffering each character to provide efficient writing. You can specify the buffer size. Generally, the default buffer size is enough. Sample Code: 2. BufferedReader-the character input buffer stream reads information from the character input stream, buffering each character to achieve efficient reading. You can specify the buffer size. Generally, the default buffer size is enough. The default size is 8192.
Sample Code: