A. Byte stream 1.inputstream/outputstream (the input stream corresponds to almost one by one of the output stream)
Method of Reading
int read ()
int read (byte[] buffer)
int read (byte[] buffer,int offset,int length)
2. Different types of distinctions, 9 commonly used (according to the basic unit of processing) 2.1. A byte array as the particle (the particle is the basic unit meaning)
Bytearrayinputstream
2.2. Take a file as a particle
FileInputStream
2.3. Pipe flow (water connection)
PipedInputStream,
Mainly used in multi-threaded inter-thread communication, a thread through the pipeline output stream to send data,
The other thread reads the data through a piped stream, which enables communication between two threads.
2.4. String as basic unit (but deprecated)
StringBufferInputStream
2.5. Special flows that combine streams (only the input stream has no corresponding class for the output stream)
sequenceinputstream : Merge multiple inputstream into one inputstream.
The sequence input stream class allows applications to merge several input streams continuously and make them appear as a single input stream.
Each input stream is read sequentially until the end of the stream is reached.
The sequence input stream class then closes the stream and automatically switches to the next input stream.
2.6. Enhanced Flow (filter stream)
FilterInputStream
2.7. Buffer Stream
Bufferedinputstream ( inherited from FilterInputStream)
2.8. Print Flow
Note:PrintStream also inherits the FilterInputStream, so it can format the input
2.9. Object-Granular
ObjectInputStream
Attached: Inheritance diagram for the Inputstream,outputstream class:
And:
*********************************************************
Character Stream 1.reader/writer: Although it is in characters, it returns the ASCII code corresponding to the character, which is the number of the int type.
Corresponding method:
int read ()
int read (char[] buffer)
int read (char[] buffer,int offset,int length)
Writer's method, more special, increased by 2:
void write (int c)
void Write (char[] cbuf)
void Write (char[] cbuf,int offset,int length)
void Write (String string)//string is closely related to character array
void Write (String string,int offset,int length)
2. Different types of distinctions, 9 commonly used (according to the basic unit of processing) 2.1. Array of characters (char) as particles
CharArrayReader (corresponds to Bytearrayinputstream, one is an array of characters, one is a byte array)
2.2. Take a file as a particle
FileReader (corresponds to Fileiputstream, but the parent class hierarchy is different, FileReader is the subclass of the conversion stream InputStreamReader, because the internal character conversion process)
2.3. Special conversion Flow (byte to character when input, character to byte when output)
InputStreamReader (FileReader is inheriting it. )
2.4. Pipeline Flow
Pipedreader (corresponds to PipedInputStream)
2.5. Character Stream
StringReader (corresponds to StringBufferInputStream)
2.6. Enhanced Flow (filter stream)
FilterReader
2.7. Buffer Stream
BufferedReader ( corresponds to Bufferedinputstream, but not inherited FilterReader)
2.8. Print the stream (since it is printing, of course only the output stream)
PrintWriter
2.9. Object-Granular
ObjectReader (corresponds to ObjectInputStream)
Special reminder, two conversion stream ********************
InputStreamReader (bytes to characters) and Outputstreamreader(characters to bytes):
1.InputStreamReader
A bridge from a byte stream to a character stream: It reads in bytes and converts it to a character stream based on the specified encoding.
The encoding used may be specified by name, or the platform can accept the default encoding method
Each invocation of one of the InputStreamReader's read () methods may cause one or more bytes to be read from the base byte input stream.
In order to achieve greater efficiency, consider packaging inputstreamreader with BufferedReader,
Such as:
BufferedReader in = new BufferedReader (new InputStreamReader (system.in));
2.OutputStreamWriter
Writes multiple characters to an output stream, converting multiple characters to bytes according to the specified character encoding
Each outputstreamwriter merges its own chartobyteconverter, and thus is the bridge from the character stream to the word stream.
Attached: Character stream Reader,writer class inheritance diagram:
And:
Introduction to Java IO input and output stream classes (with figure)