United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4772857 (cs) Need a standard way to get the default encoding
JDK-4772857 : (cs) Need a standard way to get the default encoding

Details
Type:
Enhancement
Submit Date:
2002-11-01
Status:
Resolved
Updated Date:
2003-09-26
Project Name:
JDK
Resolved Date:
2003-09-26
Component:
core-libs
OS:
solaris_8
Sub-Component:
java.nio
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
5.0 (tiger)

Related Reports
Relates:

Sub Tasks

Description
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.
I suggest

	public static Charset Charset.default();


                                    

Comments
EVALUATION

A fine idea.  -- ###@###.### 2002/11/13
                                     
179-10-11 0
WORK AROUND

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();

See
http://java.sun.com/j2se/1.4.1/docs/guide/intl/encoding.doc.html for
both old and new names.

======================================================================
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b22


                                     
2004-06-14



Hardware and Software, Engineered to Work Together