发布日期:2018-03-26
在Java中获取当前工作目录+ 查看更多
在Java中获取当前工作目录
+ 查看更多
发布日期:2018-03-10 11:46
分类:JAVA
浏览次数:64
我想使用访问我当前的工作目录
String current = new java.io.File( "." ).getCanonicalPath(); System.out.println("Current dir:"+current); String currentDir = System.getProperty("user.dir"); System.out.println("Current dir using System:" +currentDir);
输出:
当前目录:C:\ WINDOWS \ system32
当前目录使用系统:C:\ WINDOWS \ system32
当前目录使用系统:C:\ WINDOWS \ system32
我的输出不正确,因为C盘不是我当前的目录。 在这方面需要帮助。
回答
public class JavaApplication1 { public static void main(String[] args) { System.out.println("Working Directory = " + System.getProperty("user.dir")); } }这将打印一个完整的绝对路径