Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an interesting task, I have to build a graphical interface for graphical interface of another program. The issues is that the other program reads from a file but it correctly reads the data only if the windows regional format is in US format, can I launch the program using java with us regional format without changing the OS settings?

Also i'm not talking just about regional date format. And the operating system is windows 10.

Thanks.

What I have tried:

I found solutions such as locale emulator but I don't think they are applicable here.

https://www.codeproject.com/Questions/572431/Startingplusprogramplusinplusdifferentplusregional. Is one fix maybe but I don't think my program has the authority to change registry values.
Posted
Updated 25-May-21 23:09pm
Comments
Richard MacCutchan 26-May-21 4:57am    
You can set some properties for an application when you launch it. So the following command will run the application in the US locale:
java -D"user.country=US" Application
Member 15205971 26-May-21 5:07am    
Oh sorry I meant my java program has to launch non java program with different localization.

This is my code for launching the program (.exe)
ProcessBuilder processBuilder = new ProcessBuilder(file.getAbsolutePath());
processBuilder.directory(file.getParentFile());
try {
process = processBuilder.start();
...
Richard MacCutchan 26-May-21 5:12am    
That is a different issue and you would need to check the options for whatever language the other program is written in. The quickest solution would probably be to modify the original program. Most languages allow applications to set their own locale.
Member 15205971 26-May-21 5:20am    
I don't have access to the original programs source code and the application follows the current windows os locale. using your command or setDefault(Locale.US) line before calling the process didn't help. I probably can't fix it.

Thanks a lot for trying to help though. I could have been more clear in my question.
Richard MacCutchan 26-May-21 5:27am    
My answer will only work for running a Java application, which is what your question was asking about. Any normal executable runs in the default Windows locale, so needs to use the features of the Windows SDK.

1 solution

I have just confirmed the above situation (default locale is GB) and get the results below when printing the date with the following code:
Java
Date dt = new Date();
String myString = DateFormat.getDateInstance().format(dt);
System.out.printf("It is now: %s\n", myString);

C:\Users\rjmac\Documents\VSCode\Java>java test 
It is now: 26 May 2021
Java test result: 0

C:\Users\rjmac\Documents\VSCode\Java>java -D"user.country=US" test 
It is now: May 26, 2021
Java test result: 0
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900