Class PrintStreamWriter

java.lang.Object
java.io.Writer
com.globalmentor.io.PrintStreamWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class PrintStreamWriter extends Writer
Converts a PrintStream to a Writer.

This class delegates to PrintStream.print(String) for writing strings, maintaining the charset of the underlying print stream. This is especially important to maintain the charset of System.out and System.err, which virtually impossible to determine especially in earlier versions of Java. Contrast this with PrintWriter, which does not maintain the underlying charset of the PrintStream.

Author:
Garret Wilson
API Note:
Note that if System.out or System.err is being redirected, the charset may continue to be set to the console charset, which may not necessarily be the system default charset and may not be appropriate for saving to a file. This is a Java limitation and is for the most part unavoidable. It may thus be better to avoid redirecting output and instead provide options for explicitly saving to an external file with some specified or default charset. See How to find charset of System.err if stdout is redirected? for more discussion.
See Also: