• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getAbsolutePath() and getCanonicalPath()?

 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
File f1 = new File("c:\\test\\big","1.txt");
try{String s1=f1.getAbsolutePath();
String s2=f1.getCanonicalPath();
System.out.println(s1);System.out.println(s2);}
both s1 and s2 are same ?
what's the difference then ? can someone make necessary modifications in the code so that the difference between absolute and canonical path is clear ?
 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Mark
3 things to remember..
For eg: C:\...Test\test1\..file.txt
1)getPath() --> file.txt (It just returns the name of the file)
2)getCanonicalPath() --> C:\Test\test1\file.txt
(it removes ... and ..)
3)getAbsolutePath() --> C:\...Test\test1\..file.txt( inclusive of everything; even ... and ..)
HTH.
Sonir
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hope i not disturbing in your preparation but what are the dots in between ?

C:\...Test\test1\..file.txt

Originally posted by sonir shah:
Well Mark
3 things to remember..
For eg: C:\...Test\test1\..file.txt
1)getPath() --> file.txt (It just returns the name of the file)
2)getCanonicalPath() --> C:\Test\test1\file.txt
(it removes ... and ..)
3)getAbsolutePath() --> C:\...Test\test1\..file.txt( inclusive of everything; even ... and ..)
HTH.
Sonir

 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Mark..not at all..
Infact I would love to browse Javaranch especially on my last day before the exam.Infact this just makes my revision on the topics...
Actually I feel that the dots(..) must be simply any file or some directory for which we have no information and that we should'nt bother..
But I may be wrong..Because I am not sure..
but i would suggest you to better check it out in the API or JLS, if they are providing with the info.
Thanks neways.
Sonir
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A previous post
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=014068
.. means the parent directory
and . the current
reply
    Bookmark Topic Watch Topic
  • New Topic