以下代码将有助于说明我的问题:
import java.util.Locale;
import java.text.*;
public class LocaleTest {
public static void main(String[] args) {
System.out.println(Locale.getDefault());
System.out.println("java-version-" +System.getProperty("java.version"));
System.setProperty("sun.locale.formatasdefault","true");
System.out.println("prop:" +System.getProperty("sun.locale.formatasdefault"));
System.out.println("getLocale-" +Locale.getDefault());
}
}
Run Code Online (Sandbox Code Playgroud)
我们知道,在Java 7中,Locale.getDefault()中存在错误.但是,正如Oracle所建议的那样,我将系统属性"sun.locale.formatasdefault"设置为true.即使我现在正在获取我的m/c Locale,它仍然显示为en_US,即使我的m/c Locale设置为fr_BE.
以下是上述代码的输出,它是在Java 1.7.0_09上编译和运行的:
en_US java-version-1.7.0_09 prop:true getLocale-en_US
关于可能导致什么的任何想法?提前谢谢了.