If you use the TextEditorPane class, it provides handy utility methods for setting the encoding, and loading and saving with that encoding. You use it just like an RSyntaxTextArea. It's just got some extra goodies that make it useful for a true "code editor" application.

TextEditorPane textArea = new TextEditorPane();textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);FileLocation file = new FileLocation("C:/temp/test.java");// null second parameter => use system encoding, if no BOM is found.// Otherwise this parameter should be the encoding to load with if no BOM.textArea.load(file, null);textArea.setEncoding("UTF-8");textArea.save();

The TextEditorPane.load() and save() methods throw IOExceptions. setEncoding() doesn't, but it sets the dirty flag on the editor (because if you change the encoding and save, the file contents will be different than they were previously).

Alternatively, if you don't want to use TextEditorPane you can just use Java's standard java.io.package to specify the encoding to save with.

It should be UTF-8, it's just that Java does not write out a BOM when writing UTF-8 files. If you write non-ASCII characters, you'll see that they were saved correctly.

You can use org.fife.io.UnicodeWriter if you want to force writing of a BOM. UnicodeWriter (and companion UnicodeReader) are part of RSyntaxTextArea. This is actually what TextEditorPane is doing under the covers.