简体   繁体   中英

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");

And know i want to get the corresponding encoding. In this case CP1251

Is there any Framework how does this?

As commented by Sauer , Locale does not include character encoding as an attribute.

To see all attributes associated with locales, examine the Common Locale Data Repository (CLDR) maintained by the Unicode Consortium. The latest versions of OpenJDK use the CLDR by default as the source of locale information.

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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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