Java – is there a simple and safe way to convert a printwriter to a printstream?
•
Java
Is there a simple way to use Java io. The instance of printwriter is converted to Java io. PrintStream?
Solution
First, get the OutputStream from the writer See @ L_ 301_ 1@
Then pass it as a parameter to the printstream constructor:
OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os);
Update: commons IO 2.0 has writeroutputstream, so use it
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码