Java IO streams summing up

Foreword

For a long time without the Java IO streams, a lot of the basics are forgotten, yesterday wrote a piece of code, found a lot of the details are forgotten. That group within the organization at the time code review, find someone in the class IO streams associated with chaos, I still write articles, put this knowledge to sum up.

IO stream class structure in FIG.

For Java this huge system, we have to learn a piece of knowledge, only to grasp the whole, the formation of a knowledge architecture as a whole, so as to better grasp the learning content and learning direction. So, Bowen and others like up on a first-come, another blog posted to the class structure.

We Do not be in this picture so much class confused; in fact, from this chart, the structure is very clear, and it is very simple. Although the class a lot, but we used it a few, familiar with the entire call flow, we can play very happy. Now, I put a few of our common sorted out, as shown below:

From the perspective we often use it, IO stream into a byte stream and character stream, the following description and summary are expanded stream from a stream of characters and bytes.

Byte stream

Refers to a byte stream during transmission, the transmission data is a basic unit of a stream of bytes.

  • Input stream of bytes
    abstract base class for the input stream of bytes is InputStreamour most commonly subclass FileInputStreamand BufferedInputStreamtwo classes.

    FileInputStreamIs called a file input stream of bytes, meaning that the data reading operation of the file in bytes, such as reading video pictures; this we always will be used when reading the file.

    BufferedInputStreamByte stream input buffer, the BufferedInputStreamuse of the process, often used in conjunction with other flow, such as we see the BufferedInputStreamconstructor:

    BufferedInputStream(InputStream in)

    BufferedInputStreamIt is achieved through an internal buffer array of nature. For example, in the new stream corresponding to the input of a BufferedInputStreamlater, when we pass read()reading the data input stream, BufferedInputStreamit will be the input data stream into a buffer fill batches. Each time after the data in the buffer is read, the input data stream will fill the buffer again; and so forth, until we read the input data stream position. By BufferedInputStream, we can increase the processing speed and the read byte stream.

  • 字节输出流
    字节输出流的抽象基类是OutputStream,我们最常用的子类是FileOutputStreamBufferedOutputStream这两个类。

    关于字节输出流这两个常用类就不细说了,和上面的字节输入流一样。

字符流

字符流是指在传输过程中,传输数据的最基本单位是字符的流。

  • 字符输入流
    字符输入流的抽象基类是Reader,我们最常用的子类是BufferedReaderFileReader这两个类。用法不多说了。

  • 字符输出流
    字符输出流的抽象基类是Writer,我们最常用的子类是BufferedWriterFileWriter这两个类。用法也不多说了。

为啥用法不多说呢?因为明白了整个的类结构,接下来的使用也就是API的使用,我们在使用过程中需要重点关注一下编码的问题就OK了。

总结

一篇简单的总结,连代码示例都木有!希望对大家有那么一点点的帮助!

2019年7月28日 于内蒙古呼和浩特。

Guess you like

Origin www.cnblogs.com/vipygd/p/11259942.html