| Author |
java File IO doubt ?
|
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 867
|
|
please refer the java api for java.io.File at http://docs.oracle.com/javase/6/docs/api/java/io/File.html. in the constructor summary it says that
Constructor Summary
File(File parent, String child)
Creates a new File instance from a parent abstract pathname and a child pathname string.
File(String pathname)
Creates a new File instance by converting the given pathname string into an abstract pathname.
File(String parent, String child)
Creates a new File instance from a parent pathname string and a child pathname string.
i'am having hard time understanding their descriptions. for e.g in the first case what does "creates a file instance froma parent abstract pathname and a child pathname string " means.
secondly what is the difference between getAbsolutePath() and getCanonicalPath() methods ?
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3050
|
|
A lot of confusion arises from the fact that the File class doesn't actually represent files. It represents pathnames. This error was more or less corrected when the designers introduced java.nio.file.Path to replace java.io.File.
When you construct a path from a parent and child path, it simply means that the new path is a concatenation of the two paths. For instance, consider "C:\\Program Files\\Java" and "jre7\\bin". When you construct a new File object using these two paths, you will get an object representing "C:\\Program Files\\Java\\jre7\\bin".
Canonical paths are absolute paths that are also unique. You usually get them by resolving symbolic links. For instance, the path "C:\\Test\\..\\test.txt" is absolute, but it's not canonical. If you call getCanonicalPath() on the object representing this path, you would get one that represents "C:\\test.txt".
|
 |
 |
|
|
subject: java File IO doubt ?
|
|
|