我试图从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.
请给我任何建议,并帮助我解决这个问题.