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)