0

I am writing a Java application aimed at working on Windows, OSX, and Linux. The application needs save certain files periodically. I am currently on a Windows machine. How do I code the saving method, so that the files get saved consistently across all systems ? For instance, if I wanted to store a configuration file, where should I save it ?

Jenna Maiz
  • 792
  • 4
  • 17
  • 38
  • 1
    See [the answer below](http://stackoverflow.com/questions/38286433/java-cross-platform-application-where-to-save-external-files/38286495#38286495); you could use that and absolute paths, or you could also use relative paths, e.g. `new File("./Folder/file.settings")` – txtechhelp Jul 09 '16 at 21:38

2 Answers2

2

USER_HOME directory I guess is a good candidate. It should exist on all three operating systems. If you notice some famous applications like Squirrel SQL or Oracle developer studio all of them are storing their settings in the User folders. I just opened my user folder and here are the configuration folders currently present on my User folder as hidden folders:

.cups
.eclipse
.sqldeveloper
.squirrel-sql
.m2
.subversion
and so on
and so on

As you can see this is the folder of choice for the most applications.

Alexander Petrov
  • 9,204
  • 31
  • 70
0

You could use System.getProperty("os.name") to get the operating system. Based on that you could use a different directory for each of them.

I hope I understood correctly what you want to do.

r3fresh_
  • 87
  • 1
  • 8