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.