views:

205

answers:

3

I have a SWT Java app that runs on Windows XP / Vista / 7 and Mac OS X. I'm currently saving a config file to:

System.getProperty("user.home") + filename

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

This file saves information such as registration key info and it is annoying for my users if the file can't be saved or is deleted.

Is there a better path I should use?

Also, what's the preferred path for per user application data on Mac OS X?

+2  A: 

What changes in security? I understand they prohibited writing in Program Files, I didn't know they forbid to write in user home.
It would be a serious compatibility break, I have a number of applications writing there, either directly a file, or in a folder ("hidden" at the Unix mode, ie. prefixed with a dot).
Now, it seems to be more "friendly" to write in Application Data folder as do a number of other applications (but rarely cross-platform applications which seem to use the previous solution...) but the exact location seems hard to find in Java, and would need a platform detection to do something else on other platforms.

An alternative seems to be to use the Preferences API, ie. java.util.prefs.Preferences.

PhiLho
+1, Preferences API is the best solution
tulskiy
A: 

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

They moved it to c:\users\<username>\appdata\local, but had to not rely on System.getProperty("user.home") because to this day, it uses a registry KEY that can be set to incorrect value if windows is "tweaked": bug 6519127

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

The interest to keep your data within the user's homedir is that they will be part of the user's profile which can be a roaming profile, saved at logoff and restored at logon (used quite often on corporation's workstations)

VonC
A: 

OSX path for application data to be kept is "~/Library/Application Support" as per Apple documentation

Mark