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
posted
0
Anyone pl. answer.....
Deepak M
Ranch Hand
Joined: Jul 10, 2000
Posts: 124
posted
0
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
posted
0
Thanks! Deepak.But, can u explain it with an example???
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
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
posted
0
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
posted
0
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.