简体   繁体   English

Java程序可以知道它的当前目录吗?

[英]Can Java program know its current directory?

Is it possible for Java application to know the its own current directory. Java应用程序是否可以知道其自己的当前目录。 I am referring to result of pwd . 我指的是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

也许这有助于:

File cwd = new File(".");

您可以使用System.getProperty("user.dir")

This is called the working directory . 这称为工作目录。 You can get it with the following instruction : 您可以使用以下说明获取它:

System.getProperty("user.dir");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM