开发者

What is the different between getAbsolutePath and getCanonicalPath [duplicate]

开发者 https://www.devze.com 2023-04-03 06:38 出处:网络
This question already has answers here: What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java?
This question already has answers here: What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java? (开发者_C百科6 answers) Closed 4 years ago.

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.

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


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/.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号