aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes path Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "path" Watch "path" New topic
Author

path

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
what is the difference between getAbsolutePath()
and getCanonicalPath().I have read few topics here,
but i wasnt able to follow.So, anyone please explain
me .
Thanks!
[This message has been edited by avn (edited August 24, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Anyone pl. answer.....
Deepak M
Ranch Hand

Joined: Jul 10, 2000
Posts: 124
They only differ when it comes to "." and ".." directories.
Otherwise they refer to the same value !
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks! Deepak.But, can u explain it with an example???
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
The difference is more than . and .. directories. Go to "search" (see the label towards upper right corner of your screen) and search for "getCanonicalPath" and / or "getAbsolutePath" in previous discussions. There are some detailed examples.


"I'm not back." - Bill Harding, Twister
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks! Jim.But still i am not able to understand clearly.
Consider : e:/jdk1.2/bin/p1/derived.class

a)
File f1= new File("e:/jdk1.2","/./derived.class");
System.out.println("absolutepath: "+f1.getAbsolutePath());
System.out.println("canonical path: "+f1.getCanonicalPath());
o/P: e:\jdk1.2\.\derived.class
e:\jdk1.2\derived.class

b)
File f3= new File("e:/jdk1.2","/../derived.class");
System.out.println("absolutepath: "+f3.getAbsolutePath());
System.out.println("canonical path: "+f3.getCanonicalPath());
o/p: e:\jdk1.2\..\derived.class
e:\derived.class
Here , the canonical path are displayed differently???
Shouldnt it print e:\jdk1.2\bin\p1\derived.class
Pl.explain me where i am wrong??
Thanks!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Neither of the File objects you create refers to e:/jdk1.2/bin/p1/derived.class. Mostly because you never include "bin" or "p1" anywhere in the path strings which you use to initilize each File. Then, you get two different canonical paths because the File objects refer to completely different physical files, because their paths lead to different places. The ".." in the second File constructor means that anyone interpreting that path should move up one level in the directory structure, as you see in the resulting canonical path.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: path
 
Similar Threads
how to set the refresh() method for JTextarea ???
Abstract Factory Pattern Vs Factory Pattern
unable to remove spaces in xml
Help! With the formatting of the percent!
please help answer the mcq