Is there a clean and simple way to convert an instance of java.io.PrintWriter
into a java.io.PrintStream
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.