Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to use mkdir in java without knowing full path

  • You cannot reply to this topic
2 replies to this topic

#1 Manhattanisgr8   Members   -  Reputation: 486


Posted 05 August 2014 - 01:43 AM

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



#2 BitMaster   Crossbones+   -  Reputation: 3903


Posted 05 August 2014 - 01:54 AM

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.

#3 rip-off   Moderators   -  Reputation: 8120


Posted 05 August 2014 - 04:51 AM

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