Storing a file in the user's directory in cross-platform Java

cross-platform, java, path

Solution

System.getProperty("user.home")

Problem

I have a Java application that runs on Mac and Windows, directly off a CD/DVD with no installation. Now, I need to store a file containing per-user data (think favourites etc.) somewhere on the local file system, so that it can be written to. So, where do you think is a good location for this file? I am thinking something like: `<USER_DOCUMENTS_AND_SETTINGS>/application data/myapp/favourites.db` for windows `<USER_HOME_DIR>/.myapp/favourites.db` for mac/nix Thoughts? And does anyone know the best way to determine these paths within Java?

Original source

Related problems