Hi, I have a .jar that runs on various computers...sometimes Linux,
sometimes Windows, etc. Can I get the path of the directory it's
currently in so I can make a File() with it to save and load data? It's
a simple private storage file and shouldn't have to open a FileChooser.
Thanks
Dan
Abhijat Vatsyayan - 28 Nov 2005 22:04 GMT
> Hi, I have a .jar that runs on various computers...sometimes Linux,
> sometimes Windows, etc. Can I get the path of the directory it's
[quoted text clipped - 3 lines]
> Thanks
> Dan
You can use the system property "user.dir" to get the working directory.
You can also try using "." for creating the new File but I am not sure
how portable that is.
Try the following code (I have not tested it!) -
String workDirName = System.getProperty("user.dir");
File workingDir = new File(workDirName);
Notice that it is quite possible that the working directory is NOT
writable. You can also try using the other system property "user.home"
to find a directory which is usually writable.
Abhijat
daniel.w.gelder@gmail.com - 28 Nov 2005 22:23 GMT
That works fine, thank you Abhijat.