Java I/O stream classification

Source: Internet
Author: User
In Java, object operations are performed in a stream. A stream is a set of ordered data sequences in Java memory. Java reads data from the source (file, memory, keyboard, network) to the memory, forming a stream, then, these streams can be written to another destination (file, memory, console, and network), which is called a stream because the data sequence operates on different parts of the source at different times.

Ii. Classification

Stream classification: Java's stream classification is rich. People who are new to it will feel dizzy after reading it. There are many stream classification methods:

1. Input streams and output streams are divided according to the input direction. The reference object of input and output is JavaProgram.

2. The unit of data processing is different: byte stream and byte stream. The minimum unit of byte stream reading is one byte (1 byte = 8 bit ), the primary stream can read one character at a time (1 char = 2 byte = 16bit ).

3. Based on different functions, node streams are divided into node streams and processing streams. node streams read and write data directly from a source stream (this stream is not packaged or modified ), stream processing is a type of stream encapsulated on the node stream. fileinputstream is a node stream that can directly read data from the file. However, bufferedinputstream can wrap fileinputstream to provide a buffer function.

In fact, in addition to the above three categories, there are also some types that are often heard, such as object stream, buffer stream, compressed stream, and file stream. In fact, they are all subcategories of node streams and processing streams. You can also create a new stream type as long as you need it.

Iii. stream classification relationship

No matter how rich and complex stream classification is, the root cause is four basic classes. The relationships between these four classes are as follows:

Byte streams

Input stream inputstream Reader

Output stream outputstream writer

<! -- Endfragment -->

Iv. Conversion between byte streams and byte streams

1. stream from bytes to Bytes: The inputstreamreader and outputstreamwriter classes can be implemented.

2. From bytes stream to byte stream: You can get the char [] array from the bytes stream, convert it to string, and then call the string API function getbytes () to get the byte [], then, bytearrayinputstream and bytearrayoutputstream can be used to convert to byte streams.

The above knowledge is the foundation for learning Java streams, and it is very easy to perform streaming operations. Java APIs provide a wide range of stream processing classes, and the APIs are also very poor. You can get started with this by looking at the documentation.

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: 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.