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