Java Java File.getCanonicalFile()
方法具有以下語法。
public File getCanonicalFile() throws IOException
在下面的程式碼顯示如何使用File.getCanonicalFile()
方法。
import java.io.File;
// from:w w W .yI I ba i.c o M
public class Main {
public static void main(String[] args) throws Exception {
// create new files
File f = new File("test.txt");
File path = f.getCanonicalFile();
System.out.print("Absolute Pathname " + path);
}
}
上面程式碼執行結果如下 -
Absolute Pathname F:\website\yiibai\worksp\test.txt