Stream reader and writer (printwriter)

Source: Internet
Author: User

PrintwriterClass is used to replace Java 1.0PrintstreamClass, which can correctly process multi-byte character sets and international text. Sun initially planned to abandon printstream and support printwriter, but gave up the idea when it realized that doing so would invalidate too many current Code (especially code dependent on system. out. However, newly written code should still use printwriter instead of printstream.

Apart from constructors, The printwriter class also has almost the same method set as printstream. Including:

public PrintWriter(Writer out)public PrintWriter(Writer out,boolean autoFlush)public PrintWriter(OutputStream out)public PrintWriter(OutputStream out,boolean autoFlush)public void flush()public void close()public boolean checkError()public void write(int c)public void write(char[] text,int offset,int length)public void write(char[] text)public void write(String s,int offset,int length)public void write(String s)public void print(boolean b)public void print(char c)public void print(int i)public void print(long l)public void print(float f)public void print(double d)public void print(char[] text)public void print(String s)public void print(Object o)public void println()public void println(boolean b)public void println(char c)public void println(int i)public void println(long l)public void println(float f)public void println(double d)public void println(char[] text)public void println(String s)public void println(Object o)

Most of the actions of these methods are the same as those in printstream. There are only four write () methods with exceptions. They write characters instead of bytes. In addition, if the underlying writer can correctly process Character Set conversion, all printwriter methods can also process this conversion. This is an improvement for non-international printstream classes,But it is not suitable for network programming.Unfortunately, printwriter has problems such as platform dependencies that plague the printstream class and small amount of error reports.

Stream reader and writer (printwriter)

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.