Best location for properties file

I am working on a small Java application that should load / save configuration properties. At first I tried to use the properties file that lived inside the jar, but it bothered me that someone should switch to a later version (replace the existing jar), they will lose all their settings.

My next idea was to write the configuration file to disk and reference it, but I'm not sure where I have to save it. I do not want to use the current directory, because the user can move the jar between directories and forget about the configuration file.

Is there a common location for configuration property files (particularly for windows)? If so, how can I access it (I assume it will be some kind of wild card character, for example% appdata% \ my app \ config.properties)?

Thank!

+3
source share
3 answers

Try the java.util.prefs API ... while you are using Java 1.4 or later. I think that will do what you want. Some time later, I wrote several posts about them: http://coffeaelectronica.com/blog/2009/07/java-preferences-api/

Hope this helps.

+2
source

, API . .

+5

The user.home property of the system provides the path to the users home directory if you want to save it to the file system.

There is also a settings API that has been added to Java to solve this exact problem.

+2
source

Source: https://habr.com/ru/post/1729303/


All Articles