|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.File
public class File
An abstract representation of file and directory pathnames.
User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames. An abstract pathname has two components:
"/"
for the UNIX root
directory, or "\\\\"
for a Microsoft Windows UNC pathname, and
The conversion of a pathname string to or from an abstract pathname is
inherently system-dependent. When an abstract pathname is converted 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 defined by the system property file.separator
, and
is made available in the public static fields
and separator
of this class.
When a pathname string is converted 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 supported by the underlying system.
separatorChar
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 file 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
java.io
package always resolve relative pathnames against the
current user directory. This directory is named by the system property
user.dir
, and is typically the directory in which the Java
virtual machine was invoked.
The prefix concept is used to handle root directories on UNIX platforms, and drive specifiers, root directories and UNC pathnames on Microsoft Windows platforms, as follows:
"/"
. Relative pathnames have no prefix. The abstract pathname
denoting the root directory has the prefix "/"
and an empty
name sequence.
":"
and
possibly followed by "\\"
if the pathname is absolute. The
prefix of a UNC pathname is "\\\\"
; the hostname and the share
name are the first two names in the name sequence. A relative pathname that
does not specify a drive has no prefix.
Instances of the File
class are immutable; that is, once
created, the abstract pathname represented by a File
object
will never change.
Field Summary | |
---|---|
static String |
pathSeparator
The system-dependent path-separator character, represented as a string for convenience. |
static char |
pathSeparatorChar
The system-dependent path-separator character. |
static String |
separator
The system-dependent default name-separator character, represented as a string for convenience. |
static char |
separatorChar
The system-dependent default name-separator character. |
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. |
|
File(URI uri)
Creates a new File instance by converting the given file: URI into an abstract pathname. |
Method Summary | |
---|---|
boolean |
canRead()
Tests whether the application can read the file denoted by this abstract pathname. |
boolean |
canWrite()
Tests whether the application can modify the file denoted by this abstract pathname. |
int |
compareTo(File pathname)
Compares two abstract pathnames lexicographically. |
boolean |
|