File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get platforms default encoding?

 
Anamitra Bhattacharyya
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4313
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic