くどいようですが実際のファイルやディレクトリがあるとは限りません。
インスタンス変数 path の値を返すだけです。
//Sample01_01.java import java.io.File; class Sample01_01{ public static void main(String[] args){ File file = new File("pathname.txt"); String strPath = file.getPath(); System.out.println(strPath); } }
>cd ws ws>javac Sample01_01.java ws>java Sample01_01 pathname.txt
private final String path;
public String getPath() {
return path;
}
}