Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes I/O and Streams and the fly likes Better way to determine current directory... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Better way to determine current directory..." Watch "Better way to determine current directory..." New topic

Better way to determine current directory...

Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
I found that:
File currentDir = new File("");
does return the current directory that the JAR file is executing in.
Is this the best practice for doing something like this? I need to know at run time.
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
It's probably better to use

I believe the system property "user.dir" also works.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I think that technically, the meaning of "." is system-dependent. I know it means "current directory" on Unix and Windows, don't know about others. (Mac?) I use it often nonetheless, but it's probably better to use System.getProperty("user.dir") instead.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Better way to determine current directory...
Similar Threads
Path for Temporary Directory
Problem in jar file
Possible to get listing of all files in directory?
checking for existence of files/touching files
(NX:URLyBird)A question about properties files: