• 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

String getCanonicalPath() ????

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String getCanonicalPath()-Returns the canonical form of this File object's pathname
the above is a method in the File class can some one pls explain me as to what this method exactly does
AMIT
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Per the Sun API:

getCanonicalPath
public String getCanonicalPath()
throws IOException
Returns the canonical pathname string of this abstract pathname.
The precise definition of canonical form is system-dependent, but canonical forms are always absolute. Thus if this abstract pathname is relative it will be converted to absolute form as if by the getAbsoluteFile() method.
Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted.
Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
Since:
JDK1.1
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assume there is a directory c:\temp\java
File f = new File ("c:/temp/../temp/java/./..");
f.getCanonicalPath() = c:\temp\
f.getAbsolutePath() = c:\temp\..\temp\java\.\..
Canonical path is the bare minimum and neccesory path.
AbsolutePath is the Complete path with with the File object was created.
HTH,
Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add...
Consider your directory as in the explorer C:\Java\RancH and you are supplying argument to your program c:\java\ranch and here are the results.
f.getAbsolutePath() writes c:\java\ranch and
f.canonicalPath() writes C:\Java\RancH
Hope that helps to understand the mear difference.
Anna S Iyer.
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul....i get errors if i just write
File f = new File("c:\java\ranch");
and its correct as below
File f= new File("c:"+ File.separator + "java");
any details? im missing?
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try:
File f = new File("c:\\java\\ranch");
instead of :
File f = new File("c:\java\ranch");
Though :
File f= new File("c:"+ File.separator + "java");
is correct. It takes care of platform independence.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic