Java Locale.getDefault() always returns en-US on windows even though the system locale is set to a different language (through Region and Language control panel).
Running a script such as systeminfo | findstr /C:/”System Locale/ inside Java Runtime.exec() takes lot of time.
Is there a quicker way to detect system locale on (java) application startup? Running the above cmd once and writing to a property file for subsequent reads maybe one solution. But what if the system locale is changed and system restarted? What is a more reliable way to find system locale in jdk ?
Locale.getDefault(); // locale.getDisplayLanguage(); // Return current language locale.getDisplayCountry(); // Return current country
Locale.getDefault() returns the default Locale for the current JVM, NOT for the operating system.
The default Locale for the JVM defaults to en-US for most JVMs (there might be localised ones out there, I’ve never seen one).
It is possible to set it to something else using Locale.setDefault(Locale newDefault) after which Locale.getDefault() will return that Locale instead.
So one solution for your problem might be to get the default system Locale using the command you have once, set that as the new JVM default using Locale.setDefault() when starting the application, then retrieve that again using Locale.getDefault().