Reprint please indicate source: http://www.cnblogs.com/lighten/p/7071733.html
1. Preface
The previous section has already introduced the byte stream in the IO package of Java8. This chapter begins with the introduction of another important system in Java IO, the character stream. The byte is to the computer to see, the character characters is the person to be able to realize, can imagine the character stream importance. The root of the character stream system is the abstraction of the parent reader and writer. Everything originates from these two classes.
2.Reader
Reader implements the readable and closeable interfaces, both of which appear from the beginning of the JDK1.5. The structure of reader is actually very similar to InputStream, as follows:
Slightly different: The lock object Lock and Read (Charbuffer) This readable interface needs to implement the method, ready () compared to InputStream in the available (). Lock is an object that is used for synchronous operations in a stream, and for efficient use of other objects rather than the flow object itself (this. Synchronization lock using this object is inefficient? Get a new point of knowledge). The biggest difference between reader and InputStream is that the method that reader needs to implement is read (char[], int, int), and InputStream is read (). This is also well understood, because the reader character stream is more concerned with characters, can be multiple bytes, InputStream is concerned about bytes, so it is necessary to implement the Read () method.
Read a character array by reading (char[], int, int) method, and deposit into the given charbuffer.
Read () is also aided by the read (char[],int, int) method.
Maxskipbuffersize default is 8192, so you skip as many characters at a time. The rest is not to support the reset, the Close method to deal with itself.
3.Writer
Writer's differences and OutputStream are very different, the structure is as follows:
The method it needs to implement is the Write (char[],int,int), flush (), and Close () methods. The Append method is derived from the Appendable interface to which it is implemented. The default write_buffer_size is 1024.
The implementation is relatively simple, see can see clearly, here do not do a detailed description. The above structure also shows that the character stream is targeted. Writes are either characters or strings. The Append method actually calls these methods as well.
Java IO (10) Reader and writer