1

I made a JavaFX app and part of that app is that every user has settings.json file to store his settings for the app. Right now I'm storing creating and storing this file at Documents/app_folder/settings.json using the following code:

String systemUser = System.getProperty("user.name");
FileWriter file = new FileWriter(
     "/Users/" + systemUser + "/Documents/app_folder/"settings.json"
);

That one works fine only on English version of windows, on other language it doesn't work for obvious reason. Is there a way to get the system Documents folder by java code, or where should I create and store this file?

Thanks!

Michael
  • 41,989
  • 11
  • 82
  • 128
CR_244
  • 141
  • 6
  • This is not a JavaFX-specific question. Take a look at java.util.Preferences class, which allows you to store user-based preferences: https://stackoverflow.com/questions/4017137/how-do-i-save-preference-user-settings-in-java – interrupt Apr 05 '18 at 18:01

1 Answers1

2

This should be what you need:

FileSystemView.getFileSystemView().getDefaultDirectory().getPath()

another way:

System.getProperty("user.home") + File.separatorChar + "My Documents"