如何根据Java中的Locale获取相关编码?
How to get the related encoding on basis of a Locale in Java?
我搜索了很多,但没有找到任何解决方案。
我有一个例子的语言Locale locale = new Locale("ru","RU");
并且知道我想要得到相应的编码。在这种情况下 CP1251
有没有什么框架是怎么做到的?
因为 , Locale
不包含字符编码作为属性。
要查看与语言环境关联的所有属性,请检查 Common Locale Data Repository (CLDR) maintained by the Unicode Consortium. The latest versions of OpenJDK use the CLDR 默认情况下作为语言环境信息的来源。
正如同一条评论所暗示的,通常最好始终使用 UTF-8 as the character encoding unless you have a very specific reason to use another encoding. Indeed, the next release of Java, Java 18, is switching to using UTF-8 by default across all host platforms. See, JEP 400: UTF-8 by Default。
我搜索了很多,但没有找到任何解决方案。
我有一个例子的语言Locale locale = new Locale("ru","RU");
并且知道我想要得到相应的编码。在这种情况下 CP1251
有没有什么框架是怎么做到的?
因为 Locale
不包含字符编码作为属性。
要查看与语言环境关联的所有属性,请检查 Common Locale Data Repository (CLDR) maintained by the Unicode Consortium. The latest versions of OpenJDK use the CLDR 默认情况下作为语言环境信息的来源。
正如同一条评论所暗示的,通常最好始终使用 UTF-8 as the character encoding unless you have a very specific reason to use another encoding. Indeed, the next release of Java, Java 18, is switching to using UTF-8 by default across all host platforms. See, JEP 400: UTF-8 by Default。