This question already has answers here:
What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java?
(6个答案)
2年前关闭。
Java新手问题:文件类中的getAbsolutePath()和getcanonicalPath()有什么区别?我无法从文件中获得含义。在下面的代码中,它们的输出是相同的。
(6个答案)
2年前关闭。
Java新手问题:文件类中的getAbsolutePath()和getcanonicalPath()有什么区别?我无法从文件中获得含义。在下面的代码中,它们的输出是相同的。
public class copyFile {
public static void main(String[] args) throws IOException {
File inputFile = new File("/home/kit.ho/");
System.out.println("get AbsolutePath");
System.out.println(inputFile.getAbsolutePath());
System.out.println("get CanonicalPath");
System.out.println(inputFile.getCanonicalPath());
}
}
最佳答案
假设/home
实际上是/usr/home
的符号链接(symbolic link)。然后getAbsolutePath
仍将返回/home/kit.ho/
,而getCanonicalPath
将解析符号链接(symbolic link)并返回/usr/home/kit.ho/
。
关于java - getAbsolutePath和getCanonicalPath有什么区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7346656/
10-09 05:13