获取Java中的当前工作目录
方法java.lang.System.getProperty()用于获取系统属性。此系统属性由作为方法参数的键指定。要获取当前的工作目录,使用的键是user.dir。
演示此的程序如下所示-
示例
public class Demo {
public static void main(String[] argv) throws Exception {
String currentDirectory = System.getProperty("user.dir");
System.out.println("The current working directory is " + currentDirectory);
}
}上面程序的输出如下-
输出结果
The current working directory is c:\JavaProgram
现在让我们了解上面的程序。
通过使用键user.dir和方法java.lang.System.getProperty()获得当前工作目录。然后打印当前工作目录。证明这一点的代码片段如下-
String currentDirectory = System.getProperty("user.dir");
System.out.println("The current working directory is " + currentDirectory);热门推荐
10 毕业祝福语保安文案简短
11 舰长生日祝福语简短
12 求助短信生日祝福语简短
13 甄嬛传祝福语简短
14 满岁女宝祝福语简短
15 生日祝福语舅舅 简短独特
16 牛年新年祝福语大全简短
17 新年祝福语长辈简短红包
18 水晶婚夫妻祝福语简短