• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding base directory of main class file

 
Brian Snyder
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to find the base directory of an applet.
ie. getDocumentBase();
but how do I determine the base directory or where all the files in a standalone application are located?
The reason I ask is that I have created a Java software program that will be installed on an end user's machine. I need the program to be able to detrmine the base directory like the getDocumentBase() function for an applet above.
It would be nice if they placed it in c:\programName...., but that may not be the case.
They may use d:\someOtherFolder\programName....
Many thanks in advance.
Brian
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File class provides several methods for navigating a file system. getParent(), getPath(), getAbsolutePath() ...
 
Brian Snyder
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marylin,
I would like to take this a step further. So let's say I create an instance of File.
File file = new File(???);
How do I know the abstract path name to enter if the file could be different depending on the way the user installed my software?
I know it is easy to get the parent directory once a file is known, but what if where it originates (its abstract path) changes with each installation.
ie.
Some people will install as follows .... c:\Program
Some people might install as follows .... d:\Program
Maybe I need to write the starting directory in a properties file so the program can read the pathname into the program upon execution??? If so, how can I record that?
Thanks again for your help.
Brian
[This message has been edited by Brian Snyder (edited October 07, 2001).]
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this demo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic