Added in API level 1 (/guide/topics/manifest/uses-sdk-element#ApiLevels)
File
public class File
extends Object (/reference/java/lang/Object) implements Comparable
(/reference/java/lang/Comparable)<File (/reference/java/io/File)>,
Serializable (/reference/java/io/Serializable)
[Link] (/reference/java/lang/Object)
[Link]
An abstract representation of "le and directory pathnames.
User inte#aces and operating systems use system-dependent
pathname strings to name "les and directories. This class presents an
abstract, system-independent view of hierarchical pathnames. An
abstract pathname has two components:
1. An optional system-dependent pre!x string, such as a disk-drive
speci"er, "/" for the UNIX root directory, or "\\\\" for a
Microso' Windows UNC pathname, and
2. A sequence of zero or more string names.
The "rst name in an abstract pathname may be a directory name or, in
the case of Microso' Windows UNC pathnames, a hostname. Each
subsequent name in an abstract pathname denotes a directory; the
[Link] 19/12/24, 10 31 PM
Page 1 of 85
:
last name may denote either a directory or a "le. The empty abstract
pathname has no pre"x and an empty name sequence.
The conversion of a pathname string to or from an abstract pathname
is inherently system-dependent. When an abstract pathname is
conve)ed into a pathname string, each name is separated from the
next by a single copy of the default separator character. The default
name-separator character is de"ned by the system prope)y
[Link] , and is made available in the public static "elds
separator (/reference/java/io/File#separator) and separatorChar
(/reference/java/io/File#separatorChar) of this class. When a pathname
string is conve)ed into an abstract pathname, the names within it may
be separated by the default name-separator character or by any
other name-separator character that is suppo)ed by the underlying
system.
A pathname, whether abstract or in string form, may be either
absolute or relative. An absolute pathname is complete in that no
other information is required in order to locate the "le that it denotes.
A relative pathname, in contrast, must be interpreted in terms of
information taken from some other pathname. By default the classes
in the [Link] package always resolve relative pathnames against the
current user directory. This directory is named by the system prope)y
[Link] , and is typically the directory in which the Java vi)ual
machine was invoked.
The parent of an abstract pathname may be obtained by invoking the
getParent() (/reference/java/io/File#getParent()) method of this class
and consists of the pathname's pre"x and each name in the
pathname's name sequence except for the last. Each directory's
absolute pathname is an ancestor of any File object with an
absolute abstract pathname which begins with the directory's
[Link] 19/12/24, 10 31 PM
Page 2 of 85
: