Difference between getAbsolutePath and getCanonicalPath
Joined: Feb 05, 2005
What is the difference between getAbsolutePath and getCanonicalPath methods of File class.
Joined: Jul 11, 2001
A single file can have more than one absolute path, but only one canonical.
That is, if two files have different canonical paths, they are different files. The same is *not* true for absolute paths.
For example, both "C:\foo.txt" and "C:\.\foo.txt" are absolute paths that refer to the same file.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by CL Gilbert: What is the benefit of this differentiation?
As far as I can tell, comparing canonical paths is the only way to know wether two File objects reference the same physical file. I'd assume that calculating the canonical path is potentially slower and might be inapropriate to confront the user with, though.
Joined: Nov 04, 2001
Agree with Ilja. Thats why we have to use canonical path to identify symbolic links in Unix based systems.
subject: Difference between getAbsolutePath and getCanonicalPath