|
|
Setting the Locale |
If you have not assigned aLocaleto a locale-sensitive object, it will rely on theLocalereturned by the method getDefault. You can set the defaultLocalein two ways:
- Set the
user.languageanduser.regionSystem properties. TheLocaleclass sets the default by retrieving the values of these properties.- Invoke the
setDefaultmethod.These two techniques for setting the default
Localeare shown in the following example:The output of this program is as follows:import java.util.*; public class DefaultLocale { static public void main(String[] args) { Properties props = System.getProperties(); props.put("user.language", "ja"); props.put("user.region", "JA"); System.setProperties(props); Locale aLocale = Locale.getDefault(); System.out.println(aLocale.toString()); aLocale = new Locale("fr", "FR"); Locale.setDefault(aLocale); System.out.println(aLocale.toString()); } }Don't rely on the defaultja_JA fr_FRLocaleunless you set it ahead of time with one of the two methods shown above. If you don't, you may find that the theLocale returned by getDefault may not be the same on all Java platforms.
|
|
Setting the Locale |