# String getCanonicalPath() ????

Amit Roy
Ranch Hand
Posts: 132
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

Cindy Glass
"The Hood"
Sheriff
Posts: 8521
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

Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3711
10
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

Anna s Iyer
Greenhorn
Posts: 24
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.

faiza haris
Ranch Hand
Posts: 173
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?

Bharatesh H Kakamari
Ranch Hand
Posts: 198
Try:
File f = new File("c:\\java\\ranch");