0

Hello I am searching for a way to add text to an existing file in Java. I tried to use

PrintWriter outFile = new PrintWriter(new FileWriter("planetaryData.txt", true)); 

But my file is written in UTF 16-LE so I have to proceed like this:

PrintWriter outFile = new PrintWriter("file.txt","UTF-16LE");

And the FileWriter do not accept a third argument where I can add "UTF-16LE" option.

Is there a way to do it?

  • 2
    Use an OutputStreamWriter on top of a FileOutputStream. https://docs.oracle.com/javase/8/docs/api/java/io/OutputStreamWriter.html#OutputStreamWriter-java.io.OutputStream-java.nio.charset.Charset- – JB Nizet Dec 09 '17 at 22:57
  • @JBNizet Shouldn't that be an answer? – Jim Garrison Dec 10 '17 at 01:04

0 Answers0