JVM Charset.defaultCharset()不返回预期的字符集(JVM Charset.defaultCharset() does not return the expected char

编程入门 行业动态 更新时间:2024-10-24 11:24:21
JVM Charset.defaultCharset()不返回预期的字符集(JVM Charset.defaultCharset() does not return the expected charset)

我的操作系统是带有希伯来语语言环境的Windows 7,并在我的代码中使用Java 6。 我已将我的语言环境更改为英语(美国),并将显示语言更改为英语。 我重新启动了我的电脑,然后在我的java代码中尝试获取默认字符集,如下所示:

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

结果,str设置为windows-1255 。 这意味着它仍然使用希伯来语作为默认字符集。 什么似乎是问题?

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?

最满意答案

通过OpenJDK源代码, file.encoding和defaultCharset()在Windows上根据以下内容设置:

Java 6: GetUserDefaultLCID API函数,它对应于“区域和语言”控制面板小程序的“格式”选项卡上的“格式”选项。

Java 7: GetSystemDefaultLCID API函数,对应于“区域和语言”控制面板小程序的“管理”选项卡上的“非Unicode程序的语言”,除非您将sun.locale.formatasdefault Java系统属性设置为true ,这将恢复为Java 6的行为。

因此,对于Java 6,Format是要更改的设置。

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.

更多推荐

语言,str,java,Hebrew,code,电脑培训,计算机培训,IT培训"/> <meta name="descr

本文发布于:2023-07-05 01:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符集   defaultCharset   Charset   JVM   expected

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!