To convert a PrintStream to a PrintWriter , use the constructor: PrintWriter(OutputStream out)
With this constructor, you run the risk of getting the wrong encoding, since PrintStream has an encoding, but using PrintWriter(OutputStream out) ignores this and just uses the default system encoding. If you do not need a default system, you will need to save the encoding in a separate field or variable and use:
pw = new PrintWriter(new OutputStreamWriter(myPrintStream, encoding));
Where encoding can be (for example) "UTF-8" or an instance of Charset .
Eng.fouad
source share