How to change the JVM default locale?
In Java, we can use Locale.setDefault()
to change the JVM default locale.
JavaLocaleExample.java
package com.mkyong.locale;
import java.util.Locale;
public class JavaLocaleExample {
public static void main(String[] args) {
// get jvm default locale
Locale defaultLocale = Locale.getDefault();
System.out.println(defaultLocale);
// set jvm locale to china
Locale.setDefault(Locale.CHINA);
// or like this
//Locale.setDefault(new Locale("zh", "cn");
Locale chinaLocale = Locale.getDefault();
System.out.println(chinaLocale);
}
}
Output
en_US
zh_CN
Alternatively, in the command line, we can configure the user.country
and user.language
system property to change the JVM locale.
$ java -Duser.country=cn -Duser.language=zh abc
Thank you very much. This code is exactly what i was looking for. Thanks!