Best place to save program configuration file on Windows and OS X using Java?

I have a SWT Java application that runs on Windows XP / Vista / 7 and Mac OS X. I am currently saving the configuration file:

System.getProperty ("user.home") + file name

With security changes in Windows Vista and Windows 7, this doesn't seem to be the best place to save it.

This file saves information, such as information about the registration key, and it annoys my users if the file cannot be saved or deleted.

Is there a better way I should use?

Also, what is the preferred path for user application data in Mac OS X?

+4
source share
3 answers

What are the security changes? I understand that they forbade writing to Program Files, I did not know that they forbid writing to a home user.
This would be a serious compatibility gap, I have several applications writing there, either directly to a file or in a folder ("hidden" in Unix mode, ie With a dot prefix).
Now, it seems more β€œfriendly” to write in the Application Data Folder , as well as the number of other applications (but rarely cross-platform applications that seem to use the previous solution ...), but the exact location seems hard to find in Java , and discovering anything else on other platforms will require platform discovery.

An alternative, apparently, is to use java.util.prefs.Preferences .

+2
source

OSX path for storing application data - "~ / Library / Application Support" according to Apple Documentation

+1
source

Sun itself, with its java control panel, had the same problem ( bug 6487334) : their control panel, working with different integrity, could not both read and write to their deployment directories.

They ported it to c:\users\<username>\appdata\local , but should not rely on System.getProperty("user.home") because to this day it uses the registry key, which may be set to the wrong value if "tweaked" windows: error 6519127

So the question is How to get the local application data folder in Java? using HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\* , this is the right place to start looking for read and write access for your settings.
You can read it, for example, the SWT Win32 Extension project .

The interest in saving your data in a user homedir is that it will be part of a user profile, which can be a roaming profile , saved when you log out and restored when you log in (often used on corporate workstations)

0
source

All Articles