aspose file tools*
The moose likes Beginning Java and the fly likes File.getAbsolutePath() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "File.getAbsolutePath()" Watch "File.getAbsolutePath()" New topic
Author

File.getAbsolutePath()

Leroy J Brown
Ranch Hand

Joined: Dec 02, 2007
Posts: 71
A while ago I was trying to work through an i/o chapter of a Java book I was reading and was having problems figuring out where my "current directory" was so that I could tell java where to find my file to be read. A kindly JavaRanch feller gave me this code:



This was very helpful for the exercise I was working on, however I'd like to know how java determines what its "current directory" should be set to for the future. Currently I'm using eclipse and it seems eclipse does some behind the scenes stuff that I'm not aware of. Could anyone please explain how this works or point me to an article that covers this?

much obliged.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
There is a bit in the File API which I presume you have read already.
I can only presume that the "current directory" is wherever you have navigated your shell/terminal/command prompt to. Eclipse tends to set up a file called workspace, which it regards as part of the path to its current directory.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

As you see in the code, Java uses the System Property "user.dir" to determine the current working directory. What that often is system dependent.

You can control the current working directory that Java uses by setting the "user.dir" path at startup:

This is what Eclipse does. It sets the current path to the directory it uses to deploy the project to. You can configure what directory Eclipse uses by going to Run -> Open Run Dialog, go to the Arguments tab, and and choose 'Other' at the bottom of the tab under 'Working Directory', then use the File System button to find the directory you want to act as the working directory.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File.getAbsolutePath()