【发布时间】:2012-12-12 13:47:56
【问题描述】:
我正在尝试从 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());
}
类型 2:
String currentDir = System.getProperty("user.dir");
System.out.println("Current dir using System:" +currentDir);
从主类执行上述代码时,我正在获取项目目录。当我从服务器端执行时,得到“使用 System:D:\Apache Tomcat 6.0.16\bin 的当前目录”。但是我的项目位于D:\Apache Tomcat 6.0.16\wepapps\SampleStructs。
请给我任何建议并帮助我解决这个问题。
【问题讨论】:
-
项目编译完成后,您的可执行文件将被放入
\Apache Tomcat 6.0.16\bin!无论项目文件夹在哪里。 -
@codeMan 确切地说,没有可执行文件,而且 Web 应用程序也不会在 \bin 中结束。
标签: java linux jakarta-ee struts2 directory