How to use mkdir in java without knowing full path

Started by
1 comment, last by rip-off 9 years, 8 months ago

I am currently making a text based game using swing. I plan on using a wrapper to distribute the program. The question I have is; How do I make a new directory without knowing where the user installed the game? Basically I want to have something like this:

GameFolder\Data\(This is where I would want to make the new directory with the name the end user specifies)

Any help or direction would greatly be appreciated.

Cpl Alt, Travis A

USMC

Advertisement
If the user installed the game it was most likely installed in the local equivalent of "Program Files", at least on Windows. You should not try to write there at all. If you need to store data, querying System.getProperty("user.home") would probably be the way to go.

If there is no conventional installation and/or you want the application to be portable you might want to query System.getProperty("user.dir") instead. However, my last adventure in Java has been a while so I'm not sure if there are better ways. I faintly remember having asked the root ClassLoader of the application of a similar question once but you would have to check with the documentation for details or whether that really makes sense.

Searching for Java user files directory, the third result I got looks especially promising.

This topic is closed to new replies.

Advertisement