getAbsolutePath和getCanonicalPath [duplicate]之間有什么不同?

[英]What is the different between getAbsolutePath and getCanonicalPath [duplicate]


This question already has an answer here:

這個問題在這里已有答案:

Java Newbie question : what is the different between getAbsolutePath() and getcanonicalPath() in file class. I can't get the meaning from the documents. in below code, their output are the same.

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());
    }
}

1 个解决方案

#1


21  

Suppose /home was actually a symbolic link to /usr/home. Then getAbsolutePath would still return /home/kit.ho/ whereas getCanonicalPath would resolve the symlink and return /usr/home/kit.ho/.

假設/ home實際上是/ usr / home的符號鏈接。然后getAbsolutePath仍將返回/home/kit.ho/而getCanonicalPath將解析符號鏈接並返回/usr/home/kit.ho/。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/09/08/729b65d4708add605d7b480d0b44666d.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com