在Java中,你可以使用`System.getProperty("user.dir")`方法来获取当前工作目录的路径。
下面是一个示例代码片段演示如何获取当前目录路径:
public class CurrentDirectoryExample {
public static void main(String[] args) {
String currentDir = System.getProperty("user.dir");
System.out.println("当前目录路径:" + currentDir);
}
}
在上述代码中,`System.getProperty("user.dir")`方法返回一个字符串,其中包含当前工作目录的路径。然后,我们使用`System.out.println()`方法将该路径打印到控制台。
运行上述代码将输出当前目录的路径。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:linux如何获取当前目录路径