my dog learned polymorphism*
The moose likes Java in General and the fly likes how to get platforms default encoding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get platforms default encoding?" Watch "how to get platforms default encoding?" New topic
Author

how to get platforms default encoding?

Anamitra Bhattacharyya
Greenhorn

Joined: May 20, 2002
Posts: 5
Hi guys
Is there any way to get the platoforms default character encoding? I looked into the source code of the String class getBytes() method - but it uses some sun.io class to determine the encoding - which I cannot use as that is not a public API.
Any help/pointers is appreciated.
TIA
Anamitra
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

From Java Internationalization by Deitsch and Czarnecki; Ch 6 Character Sets and Unicode, pg 163
The value of the system property, file.encoding, determines the default character encoding used by the character stream classes*.
* file.encoding is not part of the Java specification, and is therefore an implementation-dependent feature.

System.out.println( System.getProperty( "file.encoding" ) );
Will give you what you want *if* that property exists.
[ June 18, 2002: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I've used
String enc = new OutputStreamWriter(System.out).getEncoding();
It's not pretty, but at least it's supported by the API. Note that the only purpose to System.out here is to supply some sort of OutputStream for the Writer constructor.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get platforms default encoding?