プロジェクトの現在のディレクトリを 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
ます。
これについて何か提案があれば教えてください。