「Java」getgetCanonicalPath()親ディレクトリの絶対パスを取得する
説明
public String getCanonicalPath()
throws IOException
戻り値:この抽象パス名と同じファイルまたはディレクトリを示す正規パス名文字列
Javaコード
package com.arkgame.study;
import java.io.File;
import java.io.IOException;
public class AbouPathDemo {
      public static void main(String[] args) {
            String rePath = "..";
            try {
                  System.out.println(new File(rePath).getCanonicalPath());
            } catch (IOException e) {
                  // TODO 自動生成された catch ブロック
                  e.printStackTrace();
            }
      }
}
結果
D:\examplePrj