获取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 婆婆高寿祝福语大全简短