This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff betw canonical and absolute

 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again!! I get it now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic