The collation of the JAVA IO package---------writer and reader

Source: Internet
Author: User

A Writer

Public abstract class Writer extends Object implements Appendable, Closeable, flushable

This class represents the input stream of the input character. Then there is a synchronization lock in this class that synchronizes the operation within the stream. And then there's this flow and FileInputStream, which is different, it provides a append method to implement append.

And then there is the Flush,write,close method. And then, since you can write characters, you can actually write to a string. Because this class does not directly deal with raw byte, it is OK to use the default character encoding.

1.PrintWriter

public class PrintWriter extends Writer

This class itself is not a stream, but also provides some methods, you can think of its internal outputstream or writer output formatted data, such as Char sequence,string,int,float,object and so on, But the raw byte is output. Remember, this is an arbitrary object that represents OutputStream. Also provides methods such as PRINT,PRINTLN.

2.OutputStreamWriter

public class OutputStreamWriter extends Writer

This class is primarily intended to provide the ability to encode characters. We can specify the encoding to use, then the encoded raw byte output to OutStream, the class itself is not a outputstream, need to use the external outputstream.

A) FileWriter

public class FileWriter extends OutputStreamWriter

This class mainly provides the ability to convert char sequence to buye[] output to file, presumably because it constructs a file output stream itself. This class uses the default encoding method.

PS: We can use OutputStreamWriter and fileoutputstream to complete the function of outputting specific encoded data to a file.

3.BufferedWriter

public class BufferedWriter extends Writer

OK, this class is also a decoration class, mainly in order to provide other writers with the function of the buff,

PS: These decorative classes can be nested in use, you can achieve a very strong function: such as printwriter out = new PrintWriter (New BufferedWriter ("Foo.out")); In this example, FileWriter is our real writer, writing to the file. The other one just provides some features for it, such as the buff, the format of the output, and so on.

4.CharArrayWriter

public class Chararraywriter extends Writer

OK, this class and Bytearrayoutputstream function is very similar, mainly used to write text to the built-in char[], the buff can be automatically grown. Then there are tochararray,tostring and other functions. There are WriteTo methods , you can write the data in the buff to another Witer object.

5.FilterWriter

Public abstract class Filterwriter extends Writer

First notice that this is an abstract class, it is also a decoration class, for other writers to provide some additional functionality. OK, this should not be written, it seems that there is no subclass. Don't use this for the time being.

6.StringWriter

public class StringWriter extends Writer 

OK, this class can be used to construct a string. It stores the written data in an internal stringbuff, which can then be tostring,getstringbuff to get the contents of the Stringbuff. The same, Close this method is also not used for any eggs.

7.PipedWriter

public class PipedWriter extends Writer  

This is similar to PipedOutputStream, except that it is a character, or char[] output to the pipe.

Two Reader

Reader extends Object implements readable, closeable

This class is similar to writer, and is read directly into the data and converted to char, or char[].

Well, this is very similar to writer, so don't summarize it.

  

The collation of the JAVA IO package---------writer and reader

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.