Deep down in the Java-API:
Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
So, if you want to write you XML-Document to a file, for the love of god, don’t use the FileWriter like this:
BufferedWriter bufout = new BufferedWriter(new FileWriter(OUTFILE)); bufout.write(out); bufout.close();
or you might end up with an XML-file that has a UTF-16 header (
encoding="UTF-16") but is encoded completely differently (plain ASCII?! Not sure…).
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(OUTFILE),"UTF-16"); out.write(s); out.close();