This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Diff betw canonical and absolute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Diff betw canonical and absolute" Watch "Diff betw canonical and absolute" New topic

Diff betw canonical and absolute

Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
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 ]


SCJP 1.2
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

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 ]

[How To Ask Questions On JavaRanch]
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Thanks again!! I get it now.
I agree. Here's the link:
subject: Diff betw canonical and absolute
It's not a secret anymore!