Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

Diff betw canonical and absolute

Sue Pillai
Ranch Hand
Posts: 89
What is the meaning of absolute path(or file) and canonical path (or file) and abstract path?
I am not able to understand the File methods because of this doubt. Can anybody explain please.. Thanks
[ February 15, 2005: Message edited by: Sue Pillai ]

Joe Ess
Bartender
Posts: 9280
10
We can create a file with a relative pathname:

That file, if it exists, is in the directory above the current working directory. Now if we want to know its path from the root directory, we use getAbsolutePath(). This method makes no attempt to resolve the path so it will be the curent working directory, two dots, then the file name (i.e. c:\java\..\test.txt). This could cause confusion should we attempt to create another file in the java directory with the same name:

Both of the files point to the same directory but the paths are different. This makes comparing files for equality (i.e. do two File instances represent the same physical file) impossible. getCanonicalPath() and getCanonicalFile() compute the path by resolving path operators (i.e. . and ..), symbolic links, drive letter case (on Windows) and so on such that a single file on a given file system has a single canonical path. We can use this canonical path (or instance, in the case of getCanonicalFile) to reliably test File instances for equality.
[ February 15, 2005: Message edited by: Joe Ess ]

Sue Pillai
Ranch Hand
Posts: 89
Thanks again!! I get it now.