• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between getAbsolutePath and getCanonicalPath

 
vicky malhotra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

What is the difference between getAbsolutePath and getCanonicalPath methods of File class.

Regards,

Vicky
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the benefit of this differentiation?
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi CL Gilbert,

I have used Canonical Paths to identify Symbolic links on Unix based systems for my application. Absolute paths won't work in that case right?

I would write down some uncompiled code sample for that here,



Its not probably 100% accurate depiction what I wanted to convey but we should get the idea...

Thanks
Maulin
[ July 11, 2005: Message edited by: Maulin Vasavada ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Ilja. Thats why we have to use canonical path to identify symbolic links in Unix based systems.

Regards
Maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic