rahul
rahul

Reputation: 215

Capturing file path in JAVA

I need to design a executable .jar which makes two text files, I want that whenever I double click the executable jar, it automatically transfer the file path to a string so that I can use it in my fileWriter up its directory so that I could give the same path for my text files.

currently I had entered the path manually in my code file. which is useless for me.

FileWriter write = new FileWriter ("D:/final project/report.txt", false);
BufferedWriter bufferedWriter = new BufferedWriter (write);

Upvotes: 1

Views: 247

Answers (2)

Edge
Edge

Reputation: 732

You should provide relative path rather than absolute path

Upvotes: 0

Andrew Logvinov
Andrew Logvinov

Reputation: 21831

I think you could use System.getProperty("user.dir") which will return current directory path.

Upvotes: 2

Related Questions