相关疑难解决方法(0)

77
推荐指数
11
解决办法
41万
查看次数

如何在java中获取当前目录?

我试图从java获取我的项目的当前目录.我使用以下代码行来获取路径详细信息.

类型1:

File directory = new File (".");
try {
    System.out.println ("Current directory's canonical path: " 
            + directory.getCanonicalPath()); 
    System.out.println ("Current directory's absolute  path: " 
                + directory.getAbsolutePath());
}catch(Exception e) {
    System.out.println("Exceptione is ="+e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

类型2:

String currentDir = System.getProperty("user.dir");
System.out.println("Current dir using System:" +currentDir);
Run Code Online (Sandbox Code Playgroud)

从主类执行上面的代码我得到项目目录.当我从服务器端执行时,得到"当前dir使用System:D:\ Apache Tomcat 6.0.16\bin".但我的项目位于D:\Apache Tomcat 6.0.16\wepapps\SampleStructs.

请给我任何建议,并帮助我解决这个问题.

java linux directory struts2 java-ee

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×2

directory ×1

java-ee ×1

javascript ×1

linux ×1

struts2 ×1