This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between getAbsolutePath() and getCanonicalPath()

 
Kevin Simonson
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Kevin Simonson
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:

Wow, I see. That's quite a difference!
 
sai rama krishna
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is only one canonical path to a file, while there can be many absolute paths to a file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic