• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

path

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone pl. answer.....
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They only differ when it comes to "." and ".." directories.
Otherwise they refer to the same value !
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! Deepak.But, can u explain it with an example???
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 am going to test your electrical conductivity with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic