Buffer stream of java IO stream, javaio

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.