Reprinted from: http://blog.csdn.net/yuebinghaoyuan/article/details/7388059
Streams in Java can be categorized from different angles.
Depending on the direction of the data flow, it can be divided into: input stream and output stream.
According to the different units of processing data can be divided into: byte stream and character stream.
According to the implementation of different functions can be divided into: node flow and processing flow.
Output stream:
Input stream:
So both the input and the output are from the point of view of the program.
BYTE stream: A read-in or read-out is a 8-bit binary.
Character Stream: A read-in or read-out is a 16-bit binary.
The principle of a byte stream and a character stream is the same, except that the units are handled differently. The suffix is stream is a byte stream, and the prefix is Reader,writer is a character stream.
Node stream: Directly connected to the data source, read in or read out.
Direct use of node flow, read and write inconvenient, in order to read and write files faster, only the processing stream.
Processing flow: With the node flow a piece of use, on the basis of the node flow, and then a layer, the socket on the node flow is the processing flow.
The stream provided by the JDK inherits four classes: InputStream (byte input stream), OutputStream (byte output stream), Reader (character input stream), Writer (character output stream).
The following are the common streams in IO in Java.
BYTE input stream:
BYTE output stream:
Character input stream:
Character output stream:
Simply introduce it:
Operation of the file: FileInputStream (Byte input stream), FileOutputStream (byte output stream), FileReader (character input stream), FileWriter (character output stream)
Operation of the pipeline: PipedInputStream (Byte input stream), Pipedoutstream (byte output stream), Pipedreader (character input stream), PipedWriter (character output stream)
An instance of PipedInputStream is used in conjunction with an instance of PipedOutputStream to complete the read-write operation of the pipeline. Mainly used for threading operations.
BYTE/character array: Bytearrayinputstream,bytearrayoutputstream,chararrayreader,chararraywriter is a byte or character array that is opened in memory.
Buffered buffer stream:: Bufferedinputstream,bufferedoutputstream,bufferedreader,bufferedwriter, is a processing stream with buffer, The main purpose of the buffer is to avoid dealing with the hard disk every time and improve the efficiency of data access.
Conversion Flow: Inputstreamreader/outputstreamwriter, converts bytes into characters.
Data flow: Datainputstream,dataoutputstream.
Because if we output a long type of 8 bytes or a float of 4 bytes, what do we do? You can output one byte at a time, or you can convert it to a string output, but it's good to have a direct output, so this data flow solves the difficulty of our output data type. Data flow can directly output float type or long type, which improves the efficiency of data reading and writing.
Print Flow: Printstream,printwriter, typically printed to the console, where you can control the printing.
Object flow: Objectinputstream,objectoutputstream, outputs the encapsulated object directly, rather than converting it into a string.
Serialized stream: Sequenceinputstream.
Object serialization: Converts the object directly to binary and writes to the media.
The use of object flow requires the implementation of the serializable interface, or an error occurs. If the member variable is modified with the transient keyword, the member variable is not written, and if the member variable of the reference type is NULL, the member variable of the value type is 0.
JAVA I/O