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 ?
Asked
Active
Viewed 236 times
0
-
1See [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 Answers
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
-
It is not really a matter of running my application on a different OS. I want to know where(i.e. which path) I should store external files so the code consistently saves across all systems. – Jenna Maiz Jul 09 '16 at 21:24
-
Ok sorry. How about the user home ? It exists on every operating system, Linux/Unix and Windows. – Alexander Petrov Jul 09 '16 at 21:25
-
-
Great I really want explanation from the person that down voted me :) – Alexander Petrov Jul 09 '16 at 21:35
-
@AlexanderPetrov: you're usually not going to get explanations, and I've found that requesting them is for naught. Not sure who or why did it. 1+ – Hovercraft Full Of Eels Jul 09 '16 at 22:05
-
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