The difference between PrintWriter and BufferedWriter

Source: Internet
Author: User

1. PrintWriter's print and println methods can accept parameters of any type, while the write method of BufferedWriter can only accept characters, array of characters, and strings;

2. PrintWriter's Println method automatically adds line wrapping, BufferedWriter needs to display the calling newline method;

3. The PrintWriter method does not throw the exception, if concerns the exception, needs to call the CheckError method to see whether has the unusual occurrence;

4. PrintWriter construction method can specify parameters, realize automatic refresh cache (AutoFlush);

5. The PrintWriter method is more widely constructed.

-------------------------------------------------------------------

PrintWriter and BufferedWriter are inherited java.io.Writer, so many functions are the same. However, PrintWriter provides a println () method to write line breaks for different platforms, and BufferedWriter can set any buffer size.
OutputStream can be passed directly to PrintWriter (BufferedWriter cannot receive), such as:
PrintWriter out
   = new PrintWriter (new Bufferedoutputstream) (New FileOutputStream ("Foo.out"));
or use OutputStreamWriter to convert OutputStream to Wrtier. Then you can use the BufferedWriter. The
API documents are well written.

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.