Deep down in the Java-API:
http://java.sun.com/javase/6/docs/api/java/io/FileWriter.html
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…).
Insted, use
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(OUTFILE),"UTF-16"); out.write(s); out.close();
Resources:
http://www.malcolmhardie.com/weblogs/angus/2004/10/23/java-filewriter-xml-and-utf-8/
Great article! That is the kind of info that are supposed to be
shared around the internet. Shame on Google for now not positioning this submit upper!
Come on over and consult with my website .
Thanks =)