Home arrow static arrow Java Programming [Archive] - How to get default system encoding?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - How to get default system encoding?
This topic has 7 replies on 1 page.

Posts:3,369
Registered: 24.10.97
How to get default system encoding?  
Jun 17, 2004 5:17 AM



 
How can i check what character encoding the underlying OS uses?
 

Posts:3,369
Registered: 24.10.97
Re: How to get default system encoding?  
Jun 17, 2004 5:24 AM (reply 1 of 7)



 
System.getProperty("file.encoding")


returns "Cp1252" on my Windows 2000 computer ... ?
 

Posts:10,972
Registered: 10/23/03
Re: How to get default system encoding?  
Jun 17, 2004 5:26 AM (reply 2 of 7)



 
[url=http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html#defaultCharset()]defaultCharset[/url]? It's not literally what you asked, but is it what you want?
 

Posts:87
Registered: 1/15/04
Re: How to get default system encoding?  
Jun 17, 2004 5:30 AM (reply 3 of 7)



 
maybe this will work...

Properties obj_properties = java.lang.System.getProperties();Enumeration obj_enum = obj_properties.properyName();// find the key from above?? // then find the match value?obj_propeties.getProperty(KEY_NAME); 
 

Posts:3,258
Registered: 00-08-28
Re: How to get default system encoding?  
Jun 17, 2004 10:06 PM (reply 4 of 7)



 
System.getProperty("file.encoding")


returns "Cp1252" on my Windows 2000 computer ... ?

I would rather go with this one.
 

Posts:11,200
Registered: 7/22/99
Re: How to get default system encoding?  
Jun 17, 2004 10:11 PM (reply 5 of 7)



 
Note that file.encoding is not a standard parameter; to get the encoding portably you should construct an InputStreamReader or a FileReader and call getEncoding().
String defaultEncoding = new InputStreamReader(              new ByteArrayInputStream(new byte[0])).getEncoding();
 

Posts:3,258
Registered: 00-08-28
Re: How to get default system encoding?  
Jun 17, 2004 10:24 PM (reply 6 of 7)



 
Note that file.encoding is not a standard parameter;
to get the encoding portably you should construct an
InputStreamReader or a FileReader and call
getEncoding().
String defaultEncoding = newInputStreamReader(new ByteArrayInputStream(newbyte[0])).getEncoding();

But this would give you the default encoding of java which is always iso8859-1 unless set otherwise. And I would guess it could be different from the OS encoding but I may be wrong here. Need to double check.
 

Posts:11,200
Registered: 7/22/99
Re: How to get default system encoding?  
Jun 17, 2004 10:30 PM (reply 7 of 7)



 
But this would give you the default encoding of java
which is always iso8859-1 unless set otherwise. And I
would guess it could be different from the OS encoding
but I may be wrong here. Need to double check.

No, it returns the system's defaut character encoding. Check the spec. (And at least on my computer the result is UTF8 which is correct.)
 
This topic has 7 replies on 1 page.