What is io:(input/output): input and output.
IO device: a device that communicates with a computer.
input device: microphone, scanner, keyboard, mouse and so on.
output Devices: monitors, printers, projectors, headphones, audio, etc.
Why does the program need IO ?
Case 1: Play game operation, score higher, store game information.
In this case, you need to store the data in the game and only store it in the file.
Case 2: Play the game, view the game heroes data stored in a file.
At this point the game program needs to read the data in the file and display it in the game.
Case 3: Upload and download operations.
Io operation is a relative process, in general, we think in terms of program (program memory)
The program needs data: The data into the program, input.
The program needs to save the data and pass the data to others: output.
Classification and operation templates for IO streams:
The classification of IO streams, standing at different angles, is not the same way:
1. Divide by flow direction: input stream and output stream.
2. Based on the unit of data: byte stream and character stream.
3. According to the function of the Division: node flow and packaging flow.
four basic streams : Byte input stream, byte output stream, character output stream, character input stream
|
BYTE stream |
Character Stream |
Output stream |
OutputStream |
Writer |
Input stream |
InputStream |
Reader |
The four basic streams are abstract classes : The other flows are inherited from the four main classes.
We cannot create four base stream objects, only their subclass objects.
No matter what the flow, there is a close method to close the resource.
If the operation of the file, the opening of a stream object associated with our disk files, if not close the resources, then the disk file has been referenced by the program, can not be deleted, and can not be modified.
template for manipulating IO streams :
Take documents for example:
1. Create a source or target object
Input operation: The data flow in the file to think of the program, at this time the file is the source, the program is the target.
Output operation: The data in the program flow to the file, at this time the file is the target, the program is the source.
2. Create an IO Stream object
Input action: Create an input stream object
Output operation: Creating an output Stream object
3. Specific IO operations
Input action: Enter the Read method of the Stream object.
Output operation: The Write method of the output stream object.
4. Close Resources
Input operation: input Stream object. Close ();
Output operation: Output stream object. Close ();
Java Core Class Library-io-io overview