This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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 ]
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.