aspose file tools*
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
Author

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.
Thanks
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
Wanderer
Sheriff

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Better way to determine current directory...