Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Java program know its current directory?

Tags:

java

Is it possible for Java application to know the its own current directory. I am referring to result of pwd.

For instance, when executed

~/Documents/workspace/Project/bin $ java com/foo/bar/baz/Runner files/text1.txt 
program should know ~/Documents/workspace/Project/bin


~/Documents/workspace/Project $ java com/foo/bar/baz/Runner files/text1.txt 
program should know ~/Documents/workspace/Project
like image 665
James Raitsev Avatar asked Feb 06 '12 15:02

James Raitsev


1 Answers

Maybe this helps:

File cwd = new File(".");
like image 183
Nim Avatar answered Sep 21 '22 09:09

Nim