| Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
| PREV | NEXT | SHOW LISTS | HIDE LISTS | ||
java.lang.Object
|
+----java.io.File
The File class is intended to provide an abstraction
that deals with most of the machine dependent complexities of
files and pathnames in a machine-independent fashion.
Note that whenever a filename or path is used it is assumed that the host's file naming conventions are used.
| Field Summary | |
| static String | pathSeparator
|
| static char | pathSeparatorChar
|
| static String | separator
|
| static char | separatorChar
|
| Constructor Summary | |
File(String path)
File instance that represents the file
whose pathname is the given path argument.
|
|
File(String path,
String name)
File instance whose pathname is the
pathname of the specified directory, followed by the separator
character, followed by the name argument.
|
|
File(File dir,
String name)
File instance that represents the file
with the specified name in the specified directory.
|
|
| Method Summary | |
| boolean | canRead()
|
| boolean | canWrite()
|
| int | compareTo(File file)
|
| int | compareTo(Object o)
|
| static File | createTempFile(String pattern,
File directory)
Creates an empty temporary file in the specified directory after a specified pattern. |
| static File | createTempFile(String prefix)
|
| boolean | delete()
|
| void | deleteOnExit()
|
| boolean | equals(Object obj)
|
| boolean | exists()
File exists.
|
| String | getAbsolutePath()
|
| String | getCanonicalPath()
File object's pathname.
|
| String | getName()
|
| String | getParent()
File
object, or null if the name has no parent part.
|
| String | getPath()
|
| int | hashCode()
|
| boolean | isAbsolute()
File object is an
absolute pathname.
|
| boolean | isDirectory()
File
object is a directory.
|
| boolean | isFile()
File
object is a "normal" file.
|
| long | lastModified()
File object was last modified.
|
| long | length()
File object.
|
| String[] | list()
File object.
|
| String[] | list(FilenameFilter filter)
File that satisfy the specified filter.
|
| boolean | mkdir()
File object.
|
| boolean | mkdirs()
File object, including any necessary parent directories.
|
| boolean | renameTo(File dest)
File object to
have the pathname given by the File argument.
|
| String | toString()
|
| Methods inherited from class java.lang.Object |
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String separator
file.separator.public static final char separatorChar
file.separator. This character
separates the directory and file components in a filename.public static final String pathSeparator
path.separator.public static final char pathSeparatorChar
path.separator. This character is
often used to separate filenames in a sequence of files given as a
"path list".| Constructor Detail |
public File(String path)
File instance that represents the file
whose pathname is the given path argument.
path
- the file pathname.
null.
public File(String path,
String name)
File instance whose pathname is the
pathname of the specified directory, followed by the separator
character, followed by the name argument.
path
- the directory pathname.
name
- the file pathname.
public File(File dir,
String name)
File instance that represents the file
with the specified name in the specified directory.
If the directory argument is null, the resulting
File instance represents a file in the
(system-dependent) current directory whose pathname is the
name argument. Otherwise, the File
instance represents a file whose pathname is the pathname of the
directory, followed by the separator character, followed by the
name argument.
dir
- the directory.
name
- the file pathname.
| Method Detail |
public String getName()
File object.public String getPath()
File object.public String getAbsolutePath()
The system property user.dir contains the current
user directory.
File.public String getCanonicalPath() throws IOException
File object's pathname.
The precise definition of canonical form is system-dependent, but it
usually specifies an absolute pathname in which all relative references
and references to the current user directory have been completely
resolved. The canonical form of a pathname of a nonexistent file may
not be defined.public String getParent()
File
object, or null if the name has no parent part. The parent
part is generally everything leading up to the last occurrence of the
separator character, although the precise definition is system
dependent. On UNIX, for example, the parent part of
"/usr/lib" is "/usr", whose parent part is
"/", which in turn has no parent. On Windows platforms,
the parent part of "c:\java" is "c:\", which
in turn has no parent.
public static File createTempFile(String pattern,
File directory) throws IOException
Creates an empty temporary file in the specified directory after a specified pattern.
Temporary files are created in the specified directory. If the specified directory is null, the default temporary directory is used. The default temporary directory may be specified using the java.io.tmpdir property. If it is not explicitely specified, it is defaulted to the underlying platform's temporary directory (such as /tmp or /var/tmp on UNIX and c:\temp on Windows).
pattern
- a patterns after which to create the temp file
name. The pattern is a string with the following syntax:
prefix{#suffix}. Assuming that the # sign may be substituted
with 8 characters, the complete pattern must result in a legal
Java filename. The prefix is mandatory. It is recommended that
the prefix be a short, meaningful string such as "hjb" or
"mail". The suffix is optional, and must be delimited with a #
character (Unicode 35). If a delimited character is to be
included in either the prefix or the suffix, it must be escaped
with the \ (Unicode 92) character. If no suffix is specified,
the file will have the ".tmp" extension. Case may not be
preserved, and if a suffix is provided, the suffix may be
truncated. If the suffix contains an extension, only the first
three characters in the extension are guaranteed to be
preserved.
directory
- the directory in which the temporary file is
to be created. If this argument is not null, the directory must
exist or an exception will be thrown. If the argument is null,
it will be defaulted to the standard temporary directory.
checkWrite method is called with the result argument
to see if the application is allowed read access to the file.public static File createTempFile(String prefix) throws IOException
This call is equivalent to calling createTempFile(String, File) with a
null argument for the directory.
pattern
- a patterns after which to create the temp file
name.
checkWrite method is called with the result argument
to see if the application is allowed read access to the file.public void deleteOnExit()
Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used carefully.
checkDelete method is called with the pathname of
this File to see if the application is allowed to
delete the file.public boolean exists()
File exists.true if the file specified by this object
exists; false otherwise.checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public boolean canWrite()
true if and only if the file system
actually contains a file specified by the path of
this file and the application is allowed
to write to the file;
false otherwise.checkWrite method is called with the pathname
of this File to see if the application is
allowed write access to the file.public boolean canRead()
true if the file specified by this object exists
and the application can read the file;
false otherwise.checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public boolean isFile()
File
object is a "normal" file.
A file is "normal" if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.
true if the file specified by this object
exists and is a "normal" file; false otherwise.checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public boolean isDirectory()
File
object is a directory.true if this File exists and is a
directory; false otherwise.checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public boolean isAbsolute()
File object is an
absolute pathname. The definition of an absolute pathname is system
dependent. For example, on UNIX, a pathname is absolute if its
first character is the separator character. On Windows platforms,
a pathname is absolute if its first character is an ASCII '\' or
'/', or if it begins with a letter followed by a colon.true if the pathname indicated by the
File object is an absolute pathname;
false otherwise.public long lastModified()
File object was last modified.
The return value is system dependent and should only be used to compare with other values returned by last modified. It should not be interpreted as an absolute time.
0L if the specified file does not exist.checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public long length()
File object.0L if the specified file does not exist.checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public boolean mkdir()
File object.true if the directory could be created;
false otherwise.checkWrite method is called with the pathname
of this File to see if the application is
allowed write access to the file.public boolean renameTo(File dest)
File object to
have the pathname given by the File argument.
dest
- the new filename.
true if the renaming succeeds;
false otherwise.checkWrite method is called both with the
pathname of this file object and with the pathname of the
destination target object to see if the application is
allowed to write to both files.public boolean mkdirs()
File object, including any necessary parent directories.true if the directory (or directories) could be
created; false otherwise.checkWrite method is called with the pathname
of each of the directories that is to be created, before
any of the directories are created.public String[] list()
File object.." and ".."
on Unix systems).checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public String[] list(FilenameFilter filter)
File that satisfy the specified filter.
filter
- a filename filter.
." and ".."
on Unix systems).checkRead method is called with the pathname
of this File to see if the application is
allowed read access to the file.public boolean delete()
true if the file is successfully deleted;
false otherwise.checkDelete method is called with the
pathname of this File to see if the
application is allowed to delete the file.public int hashCode()
File object.public boolean equals(Object obj)
true if and only if the argument is
not null and is a File object whose
pathname is equal to the pathname of this object.
obj
- the object to compare with.
true if the objects are the same;
false otherwise.public int compareTo(File file)
file
- the File to be compared.
0 if the argument File's pathname
is equal to this File's; a value less than 0 if
this File's pathname is lexicographically less than the File
argument's; and a value greater than 0 if this
File's pathname is lexicographically greater than the File
argument's.public int compareTo(Object o)
compareTo(File). Otherwise, it
throws a ClassCastException (as Files are
comparable only to other Files).
o
- the Object to be compared.
0 if the argument is a File whose
pathname is equal to this File's; a value less than
0 if the argument is a File whose pathname
is lexicographically greater than this File's; and a value
greater than 0 if the argument is a File
whosse pathname is lexicographically less than this File's.ClassCastException - if the argument is not a
File.public String toString()
| Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
| PREV | NEXT | SHOW LISTS | HIDE LISTS | ||