Well, I see you found the same workaround I did to determine the platform's default file encoding. Sad that there's no better way to do this (like a standard system property or something). Oh well. As to your question: as far as I know there's no reason to expect UTF-8 as the standard encoding on
Java platforms. There are some specific places where Java standards mandate the use of UTF-8 or something very much like it - but there are many other places where the encoding is intentionally
not mandated, instead deferring to the mysterious "platform default". The two places I know of where UTF-8 is required to be used are: (a) the class file format uses (modified) UTF-8 to represent all
String literals, and (b) the DataInput and DataOutput interfaces (implemented by RandomAccessFile and others) provide methods to readUTF() and writeUTF(). (Again, with a slightly modified version of UTF-8).
In contrast, there are many more places that default encoding creeps in if you're not careful. Anything which implicitly converts between bytes and chars is suspect. Some key places such conversion happens:
new String(byte[] bytes)
new InputStreamReader(InputStream in)
new FileReader(String fileName)
new PrintStream(OutputStream out)
new Scanner(File file)
I don't know of any standard way to change the default encoding on a machine. (Though it's entirely possible there's something in your OS which allows this.) What you can do is replace the above constructors with an alternate form that explicitly specifies an encoding:
new String(byte[] bytes, String charset)
new InputStreamReader(InputStream in, String charset)
new InputStreamReader(new FileInputStream(String fileName), String charset)
new PrintWriter(new OutputStreamWriter(OutputStream out, String charset))
new Scanner(File file, String charset)
Hope that helps...