Getting the default charset.

Hi,

I need to get the default charset of the platform that I am using. I found a workaround by using an InputStreamReader with the required parameters and calling getEncoding() method. After this, I can user Charset.forName(...). On Windows platform, I get "Windows-1252". That's ok.

This solution works but, maybe someone knows a simpler way to get the same information. This is what I would like to know.

Thanks !

[441 byte] By [Paulux1] at [2007-9-30 20:56:33]
# 1
I can't say how reliable, universal, or accurate this is, but System.getProperty("sun.jnu.encoding") gives me the value of Cp1252 in my machine, as expected.
ChuckBing at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 2
what is the meaning of a character set anyway?
Aswin at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 3
It is the set of character that is used for displaying or document encoding like an XML document (inside the header tag ?xml). Charset class Javadoc shows the character sets supported by Java. see: http://java.sun.com/j2se/1.4.2/docs/api/index.html
Paulux1 at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 4
Thank you for your help ChuckBing.As you say, went I see a property beginning with "sun.xxxxx" I am expecting that it could be Sun specific.Bye
Paulux1 at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 5
Is there a way to find the character set of a specific file? The program im writing may get input as files that may be either in ASCII or UNICODE format? how can i determine either of the formats?
Aswin at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 6
As a start, check this page that discusses Unicode and byte order marks (BOM) http://mindprod.com/jgloss/unicode.html
ChuckBing at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 7
Try this library: http://www.i18nfaq.com/chardet.html
nguyenq87 at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...
# 8

Just been looking for exactly the same thing, so Google led me here. It also lead me to this:

http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html

In Java 1.5 ( but not in earlier versions), the Charset class contains a defaultCharset() static method, defined when the JVM starts up.

Hope this helps.

mhuddie at 2007-7-7 2:29:08 > top of Java-index,Administration Tools,Sun Connection...