Difference between getAbsolutePath and getCanonicalPath
vicky malhotra
Greenhorn
Joined: Feb 05, 2005
Posts: 16
posted
0
Hi!
What is the difference between getAbsolutePath and getCanonicalPath methods of File class.
Regards,
Vicky
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
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.
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Agree with Ilja. Thats why we have to use canonical path to identify symbolic links in Unix based systems.
Regards Maulin
subject: Difference between getAbsolutePath and getCanonicalPath