+ 2

How can I work with a file in Java without knowing the path of that file?

I'm writing a simple game and so I need to storage some data of the previous matches, but I'd like to write the code in order to make it work in each directory of my pc. How can I do that?

30th Aug 2018, 6:46 PM
Gabin Jean
Gabin Jean - avatar
3 Answers
+ 5
You have to create the file each time you run the program (unless the file is already existing) and you should use System.getProperty("user.dir"); to get the current directory. Did I answered your question?
30th Aug 2018, 6:57 PM
Daniele Bonomi
Daniele Bonomi - avatar
+ 2
Yeah, you did it perfectly, thanks
30th Aug 2018, 7:01 PM
Gabin Jean
Gabin Jean - avatar
+ 1
well done Daniele Bonomi
1st Sep 2018, 12:35 AM
HRITHIK TIWARI
HRITHIK TIWARI - avatar