0

I know that every OS has a specific directory, where a program can store data. For example in macOS there is a directory called /Applications.

Where can I store program data from a java program (multi-user) on Windows, Linux and macOS? Is there a System.property?

F_Schmidt
  • 902
  • 1
  • 11
  • 32
  • You mean common to the application, not specific to the user? – Kayaman Mar 27 '20 at 17:05
  • `/Applications` is where applications are stored, not where applications store their data. – khelwood Mar 27 '20 at 17:06
  • please look into this link. https://stackoverflow.com/a/16352444/3852345 – dilly Mar 27 '20 at 17:17
  • oh yes, khelwood, my bad. dilly, your link is wrong, because I do not want to know the temp directory. I want to create a configuration file, which should be stored in a directory created by my program. And therefore I need to know the path where to create the directory. – F_Schmidt Mar 27 '20 at 17:19

1 Answers1

1

The system property user.home is a property that you can use.

Path path = Paths.get(System.getProperty("user.home"));

if (Files.isDirectory(path) && Files.exists(path)) {
    Path myFolder = path.resolve("my_folder");

    if (Files.notExists(myFolder)) {
        Files.createDirectory(myFolder);
    } 
}
Jason
  • 5,154
  • 2
  • 12
  • 22