获取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);热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短