简体   繁体   English

如何根据 Java 中的 Locale 获取相关编码?

[英]How to get the related encoding on basis of a Locale in Java?

I searched a lot, but i do not find any solution.我搜索了很多,但我没有找到任何解决方案。

I have a Language for Example Locale locale = new Locale("ru","RU");我有一个语言示例Locale locale = new Locale("ru","RU");

And know i want to get the corresponding encoding.并且知道我想获得相应的编码。 In this case CP1251在这种情况下CP1251

Is there any Framework how does this?是否有任何框架如何做到这一点?

As commented by Sauer , Locale does not include character encoding as an attribute.正如Sauer评论的Locale不包括字符编码作为属性。

To see all attributes associated with locales, examine the Common Locale Data Repository (CLDR) maintained by the Unicode Consortium.要查看与语言环境相关的所有属性,请检查由 Unicode Consortium 维护的 公共语言环境数据存储库 (CLDR) The latest versions of OpenJDK use the CLDR by default as the source of locale information.最新版本的OpenJDK默认使用 CLDR作为区域设置信息的来源。

As that same comment suggests, it is generally best to always use UTF-8 as the character encoding unless you have a very specific reason to use another encoding.正如同一评论所暗示的那样,通常最好始终使用UTF-8作为字符编码,除非您有非常具体的理由使用其他编码。 Indeed, the next release of Java, Java 18, is switching to using UTF-8 by default across all host platforms.事实上,Java 的下一个版本 Java 18 将在所有主机平台上默认切换为使用 UTF-8。 See, JEP 400: UTF-8 by Default .请参阅JEP 400: UTF-8 by Default

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM