Concept
A stream is an abstract concept of a sequence of bytes.
The file is the static storage form of the data, and the stream refers to the form of transmission.
The flow class is divided into two categories: node stream class and Filter flow class (also called process Flow Class).
The program is used to directly manipulate the target device's corresponding class called Node Stream class. The program can also invoke the node stream class through an indirect stream class to achieve more flexible and convenient reading of various types of data, which is the filter flow class (also known as the processing Stream class), or the wrapper class.
The calling procedure for the wrapper class is shown below:
The relationship of flow classification
Regardless of how rich and complex the classification of the stream is, its roots come from four basic classes. The relationship between the four classes is as follows:
Stream of Word throttling characters
Input stream InputStream Reader
Output stream OutputStream Writer
In Java, the character is stored in Unicode encoding, and the character stream processing class is responsible for converting other encoded character streams from outside to the stream of Unicode characters in Java. The class InputStreamReader and OutputStreamWriter handle the conversion of character streams and byte streams. Character streams (one buffer at a time) is more efficient than a byte stream (one bytes at a time).
InputStream
Since InputStream and OutputStream are abstact classes, they do not indicate exactly which IO device to correspond to. They have many subclasses, including networks, pipelines, memory, files, and other specific IO devices, and their various subclass objects used in the actual program.
Note: We refer to the IO source and target of the node stream class as a stream node.
Note: Write the contents of a file to the B file, the program to the operation of a file is the output class or input class this problem. The input output class is relative to the program, not the file, so we should create an input class to complete the operation of a file, create an output class to complete the operation of the B file.
OutputStream
Character-oriented stream Reader/writer
A Unicode-oriented stream that writes information from a stream to read from or to a stream in a Unicode character. Similarly, Reader/writer is also a abstact class.
Reader
Writer
IO Program code reuse:
Usually write code with--as the end of keyboard input, System.in is not directly used in the written function. Just call the function, the system.in as a parameter passed in, so that we want to read data from a file in lieu of manual keyboard input, we can directly use this function, the program does not have to do too much modification, to achieve status quo effect. the conversion between byte stream and character streams
InputStreamReader and Outputstreamreader: Converts a byte-oriented stream into a character-oriented stream.
The InputStreamReader class is a bridge from byte stream to character streams: it reads bytes and converts them to character streams according to the specified encoding.
The encoding used may be specified by name, or by the default encoding that the platform accepts.
Each invocation of one of the InputStreamReader read () methods may cause one or more bytes to be read from the base byte input stream.
To achieve greater efficiency, consider using the BufferedReader package InputStreamReader,
Bufferedreaderin = new BufferedReader (new InputStreamReader (system.in));