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).]
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
Joined: Nov 22, 2008
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!
Joined: Jan 30, 2000
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.