Wrong character encoding in XML file

After my Java code finished editing an XML file using JDOM2, the resulting project.xml has an incorrect encoding. Special characters (like italian "รจ") are not represented correctly, resulting in an unreadable character. XML Explorer (and sometimes even WinMerge) refuses to open the file.
1 answer

This one is the BEST answer!

When writing to the file, I was using Writer. The solution is switching to OutputStream.

From JDOM reference, org.jdom2.output.XMLOutputter, output(Document doc, java.io.Writer out):
Warning: using your own Writer may cause the outputter's preferred character encoding to be ignored. If you use encodings other than UTF-8, we recommend using the method that takes an OutputStream instead.