4

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?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
dalyons
  • 1,304
  • 3
  • 15
  • 23

4 Answers4

10
System.getProperty("user.home")
RichardOD
  • 28,883
  • 9
  • 61
  • 81
5

As well as user.home, the following is useful for more temporary file storage:

System.getProperty("java.io.tmpdir")
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
1

Use the Java Preferences API, designed specifically to store user preferences values in a platform independent way we all like. Java will take care of saving them and retrieving from the file or other backing store depending on the OS.

These tutorials can get you going

Community
  • 1
  • 1
n002213f
  • 7,805
  • 13
  • 69
  • 105
  • I am already using the preference API for some settings - but this is a *file* that needs storing(db file), not a string setting. – dalyons Oct 15 '09 at 08:09
  • 1
    my take was that *favourites.db* contains key-value pairs for settings. – n002213f Oct 15 '09 at 11:35
1

You can consider storing the data at Roaming directory under Windows.

denis.zhdanov
  • 3,734
  • 20
  • 25