• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Difference between getAbsolutePath and getCanonicalPath  RSS feed

 
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
 
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.
 
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?
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!