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
<I>Chance Favours the Prepared minds"</I>
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
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
"JavaRanch, where the deer and the Certified play" - David O'Meara
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2912
posted
0
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.
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.
faiza haris
Ranch Hand
Joined: Oct 17, 2000
Posts: 173
posted
0
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
Joined: Nov 09, 2000
Posts: 198
posted
0
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.