Sort various Io streams in j2se

Source: Internet
Author: User

After reading the I/O chapter, I feel like there are a lot of streams! Messy!

There are many examples in this chapter, and the relationship is also very messy. After I have learned this chapter, I basically don't know which stream is used.

Next, I will summarize how to learn about node streams and how to process stream scores to help us more easily master various streams!

The first two basic concepts are node stream and processing stream.

Node stream: you can read and write data from or to a specific place (node.

Stream processing: it is the connection and encapsulation of an existing stream. It is used to call the encapsulated stream function to read and write data.

From the concept, we can see that the stream processing is based on the node stream, and our image metaphor "stream" is a "Pipeline". So, A node stream is a pipeline directly connected to the source, and a processing stream is a pipeline built on the pipeline of the node stream.

Let's take a look at the common node stream and processing stream:

Whether it is a node stream or a processing stream, their parent class is the four abstract classes of inputstreamoutputstream reader writer.

Common node streams

File * fileinputstream fileoutputstreanfilereader filewriter

Number Groups * bytearrayinputstream bytearrayoutputstream chararrayreader chararraywriter

Node stream that processes arrays (instead of files, but an array in memory)

String * No node stream without stringreaderstringwriter processing the string

Pipeline * pipedinputstream pipedoutputstream pipedreader pipedwriter processes the pipeline node stream

 

Common stream processing:

Buffer stream * bufferedimputstrean bufferedoutputstream bufferedreader bufferedwriter ---- the parent class needs to be constructed as a parameter. The buffer function is added to avoid frequent read/write to the hard disk and buffer data size can be initialized, therefore, you must use the flush method when writing data.

Conversion stream * inputstreamreader outputstreamwriter-use inputstream or outputstream as the parameter to convert the stream from byte to bytes

Data Stream * datainputstream dataoutputstream-provides the ability to write or read the basic data type to a file. Why does this stream exist? Looking at this analysis, if there is no such stream, there is a long, which only occupies 8 bytes. If I want to write it to a file, I need to convert it into a string and convert it into a character array, the space will take up a lot, but with this stream, it is very convenient to directly write these 8 bytes to the file .. Whether it saves memory space and makes it easier to write programs. Writing is quite simple, but you should pay attention to it when reading the data. According to the Data Type Read, the pointer will move down, therefore, the write order must be consistent with the read order to fulfill your correct requirements.

 

After reading the above content, we suggest you read the API documentation. In this document, we can find that the parameters for stream processing are very special, and they are all four abstract parent classes, such as bufferedinputstream () the parameter is inputstream. So we have to think about which types of inputstream are in the node stream? Yes, it is the stream ending with inputstream.

 

So we can see at a glance what processing streams correspond to which node streams! After simple differentiation, we can find these streams! Can you see at a glance which processing stream corresponds to which node stream?

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.