Get the App
SLTechnology News&Howtos  ›  Development  › 

Buffering ideas in IO streams

Shulou Source: shulou.com Published: 2022-06-03 15:00:45 09月29日 Update

This article mainly explains the buffering thought in the IO stream. The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the buffering thought in the IO stream.

Buffer idea (because the operation speed of the memory is much faster than the original acid speed of the hard disk, so as long as you reduce the number of read and write times of the hard disk, you can improve the efficiency.)

1. The speed of byte stream reading and writing an array at a time is much faster than that of reading and writing one byte at a time.

two。 This is a buffer effect such as adding an array, and the java itself is designed at the time

3. Also taking into account this design idea (explained later in the decorative design pattern), a byte buffer stream is provided.

BufferedInputStream

1. BufferedInputStream has a built-in buffer (array)

two。 When reading a byte from BufferedInputStream

3. BufferedInputStream will read 8192 files at once, store them in the buffer, and return one to the program.

4. When the program reads it again, it doesn't have to look for the file and gets it directly from the buffer.

5. Do not re-read 8192 from the file until everything in the buffer has been used

BufferedOutputStream

1. BufferedOutputStream also has a built-in buffer (array)

two。 When a program writes bytes to the stream, it does not write directly to the file, but to the buffer first.

3. Until the buffer is full, BufferedOutputStream will not write the data in the buffer to the file at once.

Thank you for your reading, the above is the content of "buffering thought in IO flow". After the study of this article, I believe you have a deeper understanding of the buffering thought in IO stream, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Buffers buffers ideas files bytes arrays speed programs learning design disposable content hard disk obvious no memory again that is ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei Shulou Technology macOS Docker