Java IO stream sorting and javaio stream
Classes or interfaces related to Java stream operations:
Java stream class diagram structure:
Concept and function of stream
A stream is a set of sequential bytes with a starting point and an ending point. It is a general term or abstraction for data transmission. That is to say, data transmission between two devices is called a stream,The essence of a stream is data transmission. The stream is abstracted into various types based on the data transmission characteristics to facilitate more intuitive data operations.
IO stream classification
- Data types can be divided into two types: dense stream and word throttling.
- Data flows are divided into input streams and output streams.
Traffic and word throttling
The origin of the character stream: because of the different data encoding, there is a stream object for efficient character operations. In essence, when reading data based on byte streams, the specified code table is checked. Differences between byte stream and byte stream:
- Different read/write units: byte streams are measured in 8 bits and byte streams are measured in characters. Based on the ing characters in the code table, multiple bytes may be read at a time.
- Different Processing objects: byte streams can process all types of data (such as slice and avi), while character streams can only process data of character types.
Conclusion: as long as the plain text data is processed, the use of the plain stream is preferred. In addition, byte streams are used.
Input stream and output stream
Only read operations can be performed on the input stream, and only write operations can be performed on the output stream. Different streams must be used in the program based on different features of the data to be transmitted.
Java IO Stream Object
1. The Inheritance diagram of the input byte stream in InputStreamIO is displayed, as shown in the following figure:
2. Output byte stream OutputStream
The inheritance diagram of the output byte stream in IO is visible, as shown in the following figure:
3. Correspondence between input and output of byte streams
In the figure, the blue part is the main corresponding part, and the red part is the non-corresponding part.The purple dotted line indicates that these streams are usually used together.. From the figure above, we can see that the byte stream in Java IO is extremely symmetric. "Exist and make sense." Let's look at several classes that are not symmetric in these byte streams!
4. character input stream Reader
The above inheritance graph shows that:
5. character output stream Writer
The preceding graph shows that:
6. Correspondence between input and output of the livestream
7. byte stream and byte stream conversion
Conversion stream features:
When to use a conversion stream?
Specific Object embodiment:
These two stream objects are members of the character system. They have a conversion function, and they are character streams. Therefore, byte stream objects need to be input during construction.
8. File class
A File class is an object that encapsulates files and folders in a File system. You can use the object idea to operate files and folders. File class stores various metadata information about a File or directory, including the File name, File length, last modification time, whether the File is readable, and obtaining the path name of the current File, determine whether a specified file exists, obtain the file list in the current directory, and create or delete files and directories.
9. RandomAccessFile class
This object is not a member of the stream system. It encapsulates the byte stream and a buffer (character array) to operate data in the character array through internal pointers. Features:
Note: When the object is instantiated, if the file to be operated does not exist, it will be automatically created. If the file exists and the write data is not specified, it will be written from the beginning, that is, overwrite the original content.It can be used to download data in multiple threads or write data to files simultaneously.