Understanding the IO stream of Java
Stream concept: A bridge between program and data sources
Classification of Streams
In the direction of the stream (from the memory point where the program resides):
- Input stream: Reads the external input into the current program.
- Output stream: Outputs data from the current program's memory to an external
Data is divided by stream:
- BYTE stream: It deals with data units that are bytes (8bit), adaptable and powerful.
- Character stream: The data unit that it handles is characters. In general, it mainly handles text files, which are more convenient than byte streams when working with text files.
The difference between a byte stream and a character stream:
Read-write units are different: byte stream in bytes (8bit), character stream in characters, according to the Code table mapping characters, one can read multiple bytes at a time.
The processing object is different: The byte stream can handle all types of data (slices, AVI, etc.), while the character stream can only handle data of the type of characters.
Conclusion: As long as you are working with plain text data, you will prefer to use character streams. In addition, byte streams are used.
To divide by the role of a stream:
- Node Flow: Associate directly with the physical node of an IO (file on disk, network).
- Wrapper flow (processing flow): A node-based flow of the resulting stream after wrapping. All inherit the base class such as filterxxx.
IO system
The basic architecture of Java Legacy IO:
byte input stream byte output stream character input stream character output stream
Inputsteam OutputStream Reader Writer
Access file Filexxx
Accessing the array bytearrayxxx chararrayxxx
Access Pipeline Pipedxxx
Access String stringxxx
Filter Flow Fileterinputstream Fileteroutputstream Fileterreader filterwriter
Buffered Stream bufferedxxx
Print Flow PrintStream PrintWriter
Convert Stream InputStreamReader OutputStreamWriter
Special Flow DataInputStream DataOutputStream
Object Flow ObjectInputStream ObjectOutputStream
Java Basic knowledge Summary IO stream