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

3
  • 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. Commented Feb 17, 2016 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/ Commented Feb 17, 2016 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. Commented Feb 17, 2016 at 13:24

1 Answer 1

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"); 
Sign up to request clarification or add additional context in comments.

1 Comment

Please search before answering a duplicate question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.