GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes Difference between getAbsolutePath() and getCanonicalPath() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Difference between getAbsolutePath() and getCanonicalPath()" Watch "Difference between getAbsolutePath() and getCanonicalPath()" New topic
Author

Difference between getAbsolutePath() and getCanonicalPath()

Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 113
If I take a look at "http://docs.oracle.com/javase/7/docs/api/" for the documentation on class {File}, there's a method there named {getAbsolutePath()} that returns "the absolute pathname string of this abstract pathname." There's also a method named {getCanonicalPath()} that returns "the canonical pathname string of this abstract pathname." Furthermore, it says a "canonical pathname is both absolute and unique." On a Windows 7 system, when would {getAbsolutePath()} ever return anything different from what {getCanonicalPath()} does?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20



SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 113
Rob Spoor wrote:

Wow, I see. That's quite a difference!
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 265
There is only one canonical path to a file, while there can be many absolute paths to a file.
 
GeeCON Prague 2014
 
subject: Difference between getAbsolutePath() and getCanonicalPath()