Java Reference
In-Depth Information
Method
Description
getName ()
Returns a String object containing the name of the file without
the path - in other words the last name in the path stored in the
object. For a File object representing a directory, just the directory
name is returned.
getPath()
Returns a String object containing the path for the File object -
including the file or directory name.
isAbsolute()
Returns true if the File object refers to an absolute path name,
and false otherwise. Under Windows 95, 98, or NT, an absolute
path name begins with either a drive letter followed by a colon then
a backslash or a double backslash. Under Unix, an absolute path is
specified from the root directory down.
getParent()
Returns a String object containing the name of the parent
directory of the file or directory represented by the current File
object. This will be the original path without the last name. The
method returns null if there is no parent specified. This will be the
case if the File object was created for a file in the current directory
by just using a file name.
toString()
Returns a String representation of the current File object and is
called automatically when a File object is concatenated with a
String object. We have used this method implicitly in output
statements. The string that is returned is the same as that returned
by the getPath() method.
hashCode()
Returns a hash code value for the current File object. We will see
more about what hash codes are used for in Chapter 10.
equals()
You use this method for comparing two File objects for equality.
If the File object passed as an argument to the method has the
same path as the current object, the method returns true .
Otherwise, it returns false .
All of the above involve just the information encapsulated by the File object. The file or directory
itself is not queried and may or may not exist. The methods in the File class that enable you to check
out a file or directory are much more interesting and useful, so let's go directly to those next.
Search WWH ::




Custom Search