JDK-4772857 : (cs) Need a standard way to get the default encoding
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.
The NIO APIs provide neither a way get the name of the default encoding
nor a way to get the default charset. Please add a method to do this.
public static Charset Charset.default();
BugTraq+ Release Management Values
COMMIT TO FIX:
Use the system property "file.encoding" mentioned in the java tutorial
and in the javadoc for OutputStreamWriter in JDK 1.2.2. I note that this
documentation has been removed in more recent JDKs, suggesting that it
is not an officially supported mechanism. (By the way, rumor has
it that the fact that this property is the default encoding is tested
for in the java certification exams).
Name: nl37777 Date: 11/01/2002
A better workaround is to use the code
OutputStream out = new ByteArrayOutputStream();
String defaultIOEncoding = (new OutputStreamWriter(out)).getEncoding();
This will return the old java.io canonical name for the character
encoding, which is not always the same as the java.nio canonical name,
but is always supported as an alias of the corresponding java.nio
charset. If the java.nio canonical name is desired, it can be obtained by
String defaultNIOEncoding = Charset.forName(defaultIOEncoding).name();
both old and new names.