0

I know the title is a bit vague, so let me explain my explanation in more detail:

I have a Java application I want to access the directory of my application on the clients computer, to store text-files.

My problem: How can I find the file/directory of my application on the clients computer in the first place? On different platforms, file directories are different, and the client can put the application on which folder they want.

Is there an easy way to do this?

Thanks

Adam Jacksson
  • 47
  • 2
  • 8
  • Put the files to system's temp directory: `System.getProperty("java.io.tmpdir")`. This dir is purged on every restart of the OS, at least for UNIX. – Boris Pavlović Feb 17 '16 at 13:10
  • Depending on what sort of things you're trying to store, there's typically conventions assosciated with a platform. Windows has `%APPDATA%`, Mac has `~/Library/Application Support/`. Linux would typically have a hidden folder in the user's /home/ – TZHX Feb 17 '16 at 13:11
  • "Is there an easy way to do this?" - as written, where the user is responsible for putting the directory somewhere, most definitely there is absolutely no easy way to do it. Generally you make it "easy" by building in a control mechanism. Configuration file, setup tool/wizard, whatever, that allows the user to choose it in a way you can know it in the code. – Gimby Feb 17 '16 at 13:24

1 Answers1

1

I think you are looking for the User's current working directory https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties()

String dir = System.getProperty("user.dir");
Jason Plurad
  • 6,682
  • 2
  • 18
  • 37