Java IO Stream Classification:
According to the input and output is divided into: input stream, output stream, the concept of input and output stream is relative, equivalent to the pipeline on the file, the new InputStream object refers to the disk files, etc., whenever the program to read operation refers to the read data from the file, for the file is output data, However, for the program to read/Enter data, the input stream should be used, whereas the output stream should be used in the case of write operations.
According to whether the stream is directly connected to a specific place (such as disk, memory, device, etc.) into: node stream, process flow
The node stream can be directly new, and the processing flow is equivalent to a layer of pipeline on the node flow pipeline, which must be created on the basis of the node flow.
such as node stream fileinputstream in = new FileInputStream ("C:/java/a.txt");
The processing flow, as
InputStream in = new InputStream ("C:/java/a.txt");
Bufferedinputstream bin = new Bufferedinputstream (in);
Such a form with a node stream object parameter or a parent parameter construct, directly bufferedinputstream bin = new Bufferedinputstream ("C:/java/a.txt"); Ann's not on the file.
Node streams are divided into byte stream, character stream, character stream, which is read into a bytes per byte of processing (1 byte), can handle all types of data, (picture, long,float, etc.), character stream a character of one character processing (2 Byte), can only handle character type data
Parent class InputStream OutputStream (Byte stream) Reader Writer (character stream) is all abstract class
Common node streams:
Processing files FileInputStream fileoutputstream (byte stream) FileReader FileWriter (character stream)
Processing an array of programs Bytearrayinputstream Bytearrayoutputstream (Byte stream) CharArrayReader Chararraywriter (character stream)
Processing of strings (obsolete StringBufferInputStream StringBufferInputStream byte stream) StringReader StringWriter (character stream)
Pipeline processing PipedInputStream PipedOutputStream (byte stream) Pipedreader PipedWriter (character stream)
Common flow of processing:
1. Buffer stream: Bufferedinputsream bufferedoutputstream bufferedreader BufferedWriter
Such pairs like the mark () method, similar to the label
IO buffers exist to improve efficiency, put the data to be manipulated into the buffer, and then write the contents of the buffer once to the destination, rather than write once to the destination write once. It is important to note that when we close the buffer object, the stream object associated with the buffer is actually closed
.
2. Conversion Flow: InputStreamReader OutputStreamWriter
Converting byte streams into character stream is a bridge of byte flow to character stream. If you do not specify a character set encoding, the decoding process uses the default character encoding for the platform, such as: GBK.
3. Data flow: DataInputStream dataoutputstream DataReader DataWriter
Provides a way to access Java basic data types
4.Print stream: (output stream) PrintWriter PrintStream
Provides an overloaded print method that can write data directly to the pipeline without throwing exceptions, with the Auto Flush () function
5.Object Stream ObjectInputStream ObjectOutputStream
Converts an object directly into a byte stream read-write, known as the serialization of objects, must implement the Serializable interface
Transient keyword: Modify member variable, do not write this member variable
Java IO Summary