Question

Is there a clean and simple way to convert an instance of java.io.PrintWriter into a java.io.PrintStream?

Was it helpful?

Solution

First obtain an OutputStream from the Writer. See this question

Then pass it as argument to the PrintStream constructor:

OutputStream os = new WriterOutputStream(writer);
PrintStream ps = new PrintStream(os);

Update: commons-io 2.0 has WriterOutputStream, so use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top