温馨提示×

java中怎么获取当前路径

小亿
103
2023-08-18 04:04:30
栏目: 编程语言

在Java中,可以使用System.getProperty("user.dir")来获取当前工作目录的路径。

示例代码如下:

public class Main {
public static void main(String[] args) {
String currentPath = System.getProperty("user.dir");
System.out.println("当前路径:" + currentPath);
}
}

运行以上代码,将输出当前工作目录的路径。

0