0

I need help in finding a public directory of operating system where I can save a .txt file with informations.

I explain better: I have to save somewhere a txt file where I have saved some important informations but I'll have to give my program to different people from all over the world and I can't use directory that have name like "Users" because it will be translated in the language of the operating system.

So I'm looking for a directory that has the same name in all the language or better a method of an object that can let me access a public directory of the OS that can't be renamed and can be found in all OS.

Can anyone help me?

1 Answer 1

5

I good bet is System.getProperty("user.home"). From the documentation:

user.home User's home directory

This is supposed to be cross-platform and I would expect it to work regardless of the OS language/locale (the JVM should get it from the system it's running on).

I would recommend against placing files in the home directory itself; a better practice is to create a sub-directory and store your files there.

1
  • I would further recommend putting the data.txt into a sub-directory of user.home based on the package name of the main class. e.g. com.our.Main saves data to ${user.home}/com/our/data.txt. This helps avoid clashes with other apps. that want to save a data.txt that overwrites your own apps. version. ;) Apr 21, 2011 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.