java.lang.Object | +--java.io.FileAll Implemented Interfaces:
static java.lang.String | pathSeparator This is the string that is used to separate the host name from the path name in paths than include the host name. |
static char | pathSeparatorChar This is the first character of the string used to separate the host name from the path name in paths that include a host. |
static java.lang.String | separator This is the path separator string for the current host. |
static char | separatorChar This is the first character of the file separator string. |
File(java.io.File directory, java.lang.String name) This method initializes a new |
File(java.lang.String dirname, java.lang.String name) This method initializes a new |
File(java.lang.String name) This method initializes a new |
boolean | canRead() This method tests whether or not the current thread is allowed to to read the file pointed to by this object. |
boolean | canWrite() This method test whether or not the current thread is allowed to write to this object. |
int | compareTo(java.lang.Object obj) This method compares the specified |
int | compareTo(java.io.File file) This method compares the specified |
boolean | createNewFile() This method creates a new file of zero length with the same name as
the path of this |
static java.io.File | createTempFile(java.lang.String prefix, java.lang.String suffix) This method creates a temporary file in the system temporary directory. |
static synchronized java.io.File | createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory) This method creates a temporary file in the specified directory. |
synchronized boolean | delete() This method deletes the file represented by this object. |
void | deleteOnExit() Calling this method requests that the file represented by this object be deleted when the virtual machine exits. |
boolean | equals(java.lang.Object obj) This method tests two |
boolean | exists() This method tests whether or not the file represented by the object actually exists on the filesystem. |
java.io.File | getAbsoluteFile() This method returns a |
java.lang.String | getAbsolutePath() This method returns the path of this file as an absolute path name. |
java.io.File | getCanonicalFile() This method returns a |
java.lang.String | getCanonicalPath() This method returns a canonical representation of the pathname of this file. |
java.lang.String | getName() This method returns the name of the file. |
java.lang.String | getParent() This method returns a |
java.io.File | getParentFile() This method returns a |
java.lang.String | getPath() Returns the path name that represents this file. |
int | hashCode() This method returns a hash code representing this file. |
boolean | isAbsolute() This method returns true if this object represents an absolute file path and false if it does not. |
boolean | isDirectory() This method tests whether or not the file represented by this object is a directory. |
boolean | isFile() This method tests whether or not the file represented by this object is a "plain" file. |
boolean | isHidden() This method tests whether or not this file represents a "hidden" file. |
long | lastModified() This method returns the last modification time of this file. |
long | length() This method returns the length of the file represented by this object, or 0 if the specified file does not exist. |
java.lang.String[] | list() This method returns a array of |
java.lang.String[] | list(java.io.FilenameFilter filter) This method returns a array of |
java.io.File[] | listFiles() This method returns an array of |
java.io.File[] | listFiles(java.io.FilenameFilter filter) This method returns an array of |
java.io.File[] | listFiles(java.io.FileFilter filter) This method returns an array of |
static java.io.File[] | listRoots() This method returns an array of filesystem roots. |
boolean | mkdir() This method creates a directory for the path represented by this object. |
boolean | mkdirs() This method creates a directory for the path represented by this file. |
synchronized boolean | renameTo(java.io.File dest) This method renames the file represented by this object to the path
of the file represented by the argument |
boolean | setLastModified(long time) This method sets the modification time on the file to the specified value. |
boolean | setReadOnly() This method sets the file represented by this object to be read only. |
java.lang.String | toString() This method returns a |
java.net.URL | toURL() This method returns a |
public static final String pathSeparator
path.separator
system property.
public static final char pathSeparatorChar
path.separator
system property.
public static final String separator
file.separator
system property.
An example separator string would be "/" on the GNU system.
public static final char separatorChar
file.separator
system property.
public File(java.io.File directory, java.lang.String name)
File
object to represent
a file in the specified directory. If the directory
argument is null
, the file is assumed to be in the
current directory as specified by the user.dir
system
property
directory
- The directory this file resides inname
- The name of the filepublic File(java.lang.String name)
File
object to represent
a file with the specified path.
name
- The path name of the filepublic File(java.lang.String dirname, java.lang.String name)
File
object to represent
a file in the specified named directory. The path name to the file
will be the directory name plus the separator string plus the file
name. If the directory path name ends in the separator string, another
separator string will still be appended.
dirname
- The path to the directory the file resides inname
- The name of the filepublic boolean canRead()
SecurityManager
(if any) allows access to the file via it's checkRead
method 3) the file is readable.
true
if reading is allowed, false
otherwiseSecurityException
- If the SecurityManager
does not allow access to the filepublic boolean canWrite()
SecurityManager
(if any) allows write access to the
file and 2) The file exists and 3) The file is writable. To determine
whether or not a non-existent file can be created, check the parent
directory for write access.
true
if writing is allowed, false
otherwiseSecurityException
- If the SecurityManager
does not allow access to the filepublic int compareTo(java.io.File file)
File
to this one
to test for equality. It does this by comparing the canonical path names
of the files.
The canonical paths of the files are determined by calling the
getCanonicalPath
method on each object.
This method returns a 0 if the specified Object
is equal
to this one, a negative value if it is less than this one
a positive value if it is greater than this one.
file
- public int compareTo(java.lang.Object obj)
Object
to this one
to test for equality. It does this by comparing the canonical path names
of the files. This method is identical to compareTo(File)
except that if the Object
passed to it is not a
File
, it throws a ClassCastException
The canonical paths of the files are determined by calling the
getCanonicalPath
method on each object.
This method returns a 0 if the specified Object
is equal
to this one, a negative value if it is less than this one
a positive value if it is greater than this one.
obj
- ClassCastException
- If the passed Object
is not a File
public boolean createNewFile()
File
object if an only if that file
does not already exist.
A SecurityManager
checkWrite check is done prior
to performing this action.
true
if the file was created, false
if
the file alread existed.IOException
- If an I/O error occursSecurityException
- If the SecurityManager
will
not allow this operation to be performed.public static File createTempFile(java.lang.String prefix, java.lang.String suffix)
java.io.tmpdir
system property.
The prefix
parameter is a sequence of at least three
characters that are used as the start of the generated filename. The
suffix
parameter is a sequence of characters that is used
to terminate the file name. This parameter may be null
and if it is, the suffix defaults to ".tmp".
If a SecurityManager
exists, then its checkWrite
method is used to verify that this operation is permitted.
This method is identical to calling
createTempFile(prefix, suffix, null)
.
prefix
- The character prefix to use in generating the path name.suffix
- The character suffix to use in generating the path name.IllegalArgumentException
- If the prefix or suffix are not valid.SecurityException
- If there is no permission to perform this operationIOException
- If an error occurspublic static synchronized File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory)
java.io.tmpdir
system property.
The prefix
parameter is a sequence of at least three
characters that are used as the start of the generated filename. The
suffix
parameter is a sequence of characters that is used
to terminate the file name. This parameter may be null
and if it is, the suffix defaults to ".tmp".
If a SecurityManager
exists, then its checkWrite
method is used to verify that this operation is permitted.
prefix
- The character prefix to use in generating the path name.suffix
- The character suffix to use in generating the path name.directory
- The directory to create the file in, or null
for the default temporary directoryIllegalArgumentException
- If the patterns is not validSecurityException
- If there is no permission to perform this operationIOException
- If an error occurspublic synchronized boolean delete()
true
if the file was deleted, false
otherwiseSecurityException
- If deleting of the file is not allowedpublic void deleteOnExit()
SecurityException
- If deleting of the file is not allowedpublic boolean equals(java.lang.Object obj)
File
objects for equality by
comparing the path of the specified File
against the path
of this object. The two objects are equal if an only if 1) The
argument is not null 2) The argument is a File
object and
3) The path of the File
argument is equal to the path
of this object.
The paths of the files are determined by calling the getPath()
method on each object.
obj
- true
if the two objects are equal, false
otherwise.public boolean exists()
true
if the file exists, false
otherwise.SecurityException
- If reading of the file is not permittedpublic File getAbsoluteFile()
File
object representing the
absolute path of this object.
File
with the absolute path of the object.public String getAbsolutePath()
user.dir
system property.
public File getCanonicalFile()
File
object representing the
canonical path of this object.
File
instance representing the canonical path of
this object.IOException
- If an error occurs.public String getCanonicalPath()
Note that this method, unlike the other methods which return path names, can throw an IOException. This is because native method might be required in order to resolve the canonical path
IOException
- If an error occurspublic String getName()
public String getParent()
String
the represents this file's
parent. null
is returned if the file has no parent. The
parent is determined via a simple operation which removes the
public File getParentFile()
File
object representing the parent
file of this one.
public String getPath()
public int hashCode()
getPath()
)
exclusived or-ed with the value 1234321.
public boolean isAbsolute()
true
if this object represents an absolute file name, false
otherwise.public boolean isDirectory()
true
,
the file represented by this object must exist and be a directory.
true
if this file is a directory, false
otherwiseSecurityException
- If reading of the file is not permittedpublic boolean isFile()
true
if this is a plain file, false
otherwiseSecurityException
- If reading of the file is not permittedpublic boolean isHidden()
true
if the file is hidden, false
otherwise.public long lastModified()
If the file does not exist, then a value of 0 is returned.
SecurityException
- If reading of the file is not permittedpublic long length()
SecurityException
- If reading of the file is not permittedpublic String[] list()
String
's representing the
list of files is then directory represented by this object. If this
object represents a non-directory file or a non-existent file, then
null
is returned. The list of files will not contain
any names such as "." or ".." which indicate the current or parent
directory. Also, the names are not guaranteed to be sorted.
A SecurityManager
check is made prior to reading the
directory. If read access to the directory is denied, an exception
will be thrown.
null
if this object does not represent a valid directory.SecurityException
- If read access is not allowed to the directory by the SecurityManager
public String[] list(java.io.FilenameFilter filter)
String
's representing the
list of files is then directory represented by this object. If this
object represents a non-directory file or a non-existent file, then
null
is returned. The list of files will not contain
any names such as "." or ".." which indicate the current or parent
directory. Also, the names are not guaranteed to be sorted.
In this form of the list()
method, a filter is specified
that allows the caller to control which files are returned in the
list. The FilenameFilter
specified is called for each
file returned to determine whether or not that file should be included
in the list.
A SecurityManager
check is made prior to reading the
directory. If read access to the directory is denied, an exception
will be thrown.
filter
- An object which will identify files to exclude from the directory listing.null
if this object does not represent a valid directory.SecurityException
- If read access is not allowed to the directory by the SecurityManager
public File[] listFiles()
File
objects representing
all the files in the directory represented by this object. If this
object does not represent a directory, null
is returned.
Each of the returned File
object is constructed with this
object as its parent.
A SecurityManager
check is made prior to reading the
directory. If read access to the directory is denied, an exception
will be thrown.
File
objects for this directory.SecurityException
- If the SecurityManager
denies
access to this directory.public File[] listFiles(java.io.FileFilter filter)
File
objects representing
all the files in the directory represented by this object. If this
object does not represent a directory, null
is returned.
Each of the returned File
object is constructed with this
object as its parent.
In this form of the listFiles()
method, a filter is specified
that allows the caller to control which files are returned in the
list. The FileFilter
specified is called for each
file returned to determine whether or not that file should be included
in the list.
A SecurityManager
check is made prior to reading the
directory. If read access to the directory is denied, an exception
will be thrown.
filter
- File
objects for this directory.SecurityException
- If the SecurityManager
denies
access to this directory.public File[] listFiles(java.io.FilenameFilter filter)
File
objects representing
all the files in the directory represented by this object. If this
object does not represent a directory, null
is returned.
Each of the returned File
object is constructed with this
object as its parent.
In this form of the listFiles()
method, a filter is specified
that allows the caller to control which files are returned in the
list. The FilenameFilter
specified is called for each
file returned to determine whether or not that file should be included
in the list.
A SecurityManager
check is made prior to reading the
directory. If read access to the directory is denied, an exception
will be thrown.
filter
- File
objects for this directory.SecurityException
- If the SecurityManager
denies
access to this directory.public static File[] listRoots()
File
objects for each filesystem root
available.public boolean mkdir()
true
if the directory was created, false
otherwiseSecurityException
- If write access is not allowed to this filepublic boolean mkdirs()
true
if the directory was created, false
otherwiseSecurityException
- If write access is not allowed to this filepublic synchronized boolean renameTo(java.io.File dest)
File
.
dest
- The File
object representing the target nametrue
if the rename succeeds, false
otherwise.SecurityException
- If write access is not allowed to the file by the SecurityMananger
.public boolean setLastModified(long time)
time
- The desired modification time.true
if the operation succeeded, false
otherwise.IllegalArgumentException
- If the specified time is negative.SecurityException
- If the SecurityManager
will
not allow this operation.public boolean setReadOnly()
true
if the operation succeeded, false
otherwise.SecurityException
- If the SecurityManager
does
not allow this operation.public String toString()
String
that is the path name of the
file as returned by getPath
.
String
representation of this filepublic URL toURL()
URL
with the file:
protocol that represents this file. The exact form of this URL is
system dependent.
URL
for this object.MalformedURLException
- If the URL cannot be created successfully.