Java 除了从windows属性而不是JVM获取国家ISO-2代码外,还有其他方法吗
基本上正如标题所述,我已经尝试过:Java 除了从windows属性而不是JVM获取国家ISO-2代码外,还有其他方法吗,java,windows,jvm,locale,Java,Windows,Jvm,Locale,基本上正如标题所述,我已经尝试过: Locale currentLocale=Locale.getDefault(); System.out.println(currentLocale.getDisplayLanguage()); System.out.println(currentLocale.getDisplayCountry()); System.out.println(currentLocale.getLanguage()); System.out.println(currentLoca
Locale currentLocale=Locale.getDefault();
System.out.println(currentLocale.getDisplayLanguage());
System.out.println(currentLocale.getDisplayCountry());
System.out.println(currentLocale.getLanguage());
System.out.println(currentLocale.getCountry());
System.out.println(System.getProperty(“user.country”);
System.out.println(System.getProperty(“user.language”);
当我在寡妇的环境中设置了完全不同的东西时,这一切都给了我我们或英语。
请给我任何建议。
因此,我希望得到有争议的代码,例如,如果我在系统中设置了Poland,我希望是“PL”,但我得到的是“US”默认Java语言环境不一定与系统语言环境相同,因为它可以被覆盖
- 具有
、user.country
和user.language
系统属性李>user.variant
- 通过调用
Locale.setDefault()
import sun.util.locale.provider.HostLocaleProviderAdapter;
...
static String getHostCountry() {
for (Locale locale : new HostLocaleProviderAdapter().getAvailableLocales()) {
if (!locale.getCountry().isEmpty()) {
return locale.getCountry();
}
}
return null;
}
默认Java语言环境不必与系统语言环境相同,因为它可以被重写
- 具有
、user.country
和user.language
系统属性李>user.variant
- 通过调用
Locale.setDefault()
import sun.util.locale.provider.HostLocaleProviderAdapter;
...
static String getHostCountry() {
for (Locale locale : new HostLocaleProviderAdapter().getAvailableLocales()) {
if (!locale.getCountry().isEmpty()) {
return locale.getCountry();
}
}
return null;
}
请提供您期望的输出示例,以及您看到的输出。请提供您期望的输出示例,而您看到的输出。linux呢?@DamianHong MinhNguyen在linux上只需检查
LC_ALL
和LANG
环境变量。linux呢?@DamianHong MinhNguyen在linux上只需检查LC_ALL
和LANG
环境变量。