The moose likes I/O and Streams and the fly likes finding current directory Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "finding current directory" Watch "finding current directory" New topic
Author

finding current directory

Brian Coates
Ranch Hand

Joined: Jul 03, 2001
Posts: 42
Is there a way to find out the directory that a class file is being ran in. The goal her is that someone could put my class file anywhere on their machine, and I could find the path of where that is.
I've checked the java.io.File methods, and it doesn't seem to have what I'm looking for.
Thanks.
Les Dsouza
Greenhorn

Joined: Jan 29, 2002
Posts: 27
You can try
System.getProperty("user.dir")

hope this helps.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I haven't tried it, but I think someone once recommended new File(".")...
DOM


[ JavaRanch FAQ ][ Book Promotions ][ DbTamer ][ BumperStickers ][ JavaRanch Badges ]
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Ya it's new File(".").getName() gives u the current directory.U can use .getPath() to get the whole path also.
Happy middling with java.
Netharam
Brian Coates
Ranch Hand

Joined: Jul 03, 2001
Posts: 42
thanks, i'll give that a try.
 
 
subject: finding current directory
 
Threads others viewed
Size of Objects in Memory
pass servlet value into java program it is in different application
read file replace string
Why does java not allow multiple public classes in a java file ?
Strange Error
IntelliJ Java IDE