2

My OS is windows 7 with Hebrew locale and using Java 6 in my code. I've changed my locale to English(United States) and also the display language to English. I restarted my PC and then in my java code tried to get the default charset as follow:

String str = Charset.defaultCharset().name();

The result, str is set to windows-1255.
Which means that it still using the Hebrew as the default charset.
What seems to be the problem?

Snow
  • 339
  • 1
  • 5
  • 20

1 Answers1

2

Going by OpenJDK sources, file.encoding and thus defaultCharset() is set on Windows according to:

Java 6: GetUserDefaultLCID API function which corresponds to the Format option on the Formats tab of the Region and Language control panel applet.

Java 7: GetSystemDefaultLCID API function which corresponds to the "Language for non-Unicode programs" on the Administrative tab of the Region and Language control panel applet, unless you set the sun.locale.formatasdefault Java system property to true, which will revert to the Java 6 behavior.

So for Java 6 the Format is the setting to change.

cynic
  • 5,305
  • 1
  • 24
  • 40
  • Yes I did. In addition, I've changed also the language display to English in keyboards and Languages although it is not the setting that matters. – Snow Oct 30 '12 at 08:28
  • It works for me with Oracle's JDK 7 on Windows 7. Which is strange, because I looked up the OpenJDK sources for both Java 6 and 7 and the file.encoding system property (which is what `defaultCharset()` uses to determine the default charset) is set according to result of `GetUserDefaultLCID` Win32 function, corresponding to the Format option on the Formats tab of the Region and Language control panel applet, not the `GetSystemDefaultLCID` which is the "Language for non-Unicode programs". Could you try changing the "Format" as well to see if there's any change? I'll correct my answer then. – cynic Oct 30 '12 at 09:43
  • You are absolutly right! When I changed the Format I got the correct default Charset. – Snow Nov 06 '12 at 14:52