I'm writing an Application for Mac in Java that needs to store a few preference files. By default, they seem to be storing to the User folder, but I'd like to store the files in the Library/ApplicationSupport folder, but I can't seem to figure out how to do that.
I've tried File file = new File("/Library/ApplicationSupport/AppName");
then file.mkdir()
but it keeps returning false. I've tried adding ~
to the front of /Library/
, and that didn't work either.
I've also tried just writing the file to the desired directory on a FileOutputStream, but no luck there either. I'm open to other ways of storing my preference files, I just don't want them stored in an obtrusive way to the user.
Thanks!
You can't write to /Library/ApplicationSupport
because your user would not have the permission.
The plain Java io classes don't understand "~", so to write to ~/Library/ApplicationSupport
, you need:
System.getProperty("user.home") + "/Library/ApplicationSupport"