Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Load/save text file where application is.

Thread view: 
daniel.w.gelder@gmail.com - 28 Nov 2005 21:49 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
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.