Is there an easy and safe way to convert PrintWriter to PrintStream?

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

+6
source share
1 answer

First, get an OutputStream from Writer . See this question

Then pass it as an argument to the PrintStream constructor:

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

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

+10
source

All Articles