|
|
canRead
public boolean canRead(
)
Tests whether the application can read the file denoted by this
abstract pathname.
canWrite
public boolean canWrite(
)
Tests whether the application can modify to the file denoted by this
abstract pathname.
compareTo
public int compareTo(
File pathname
)
Compares two abstract pathnames lexicographically. The ordering
defined by this method depends upon the underlying system. On UNIX
systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows
systems it is not.
compareTo
public int compareTo(
Object o
)
Compares this abstract pathname to another object. If the other object
is an abstract pathname, then this function behaves like compareTo(File). Otherwise, it throws a
ClassCastException, since abstract pathnames can only be
compared to abstract pathnames.
createNewFile
public boolean createNewFile(
)
throws
IOException
Atomically creates a new, empty file named by this abstract pathname if
and only if a file with this name does not yet exist. The check for the
existence of the file and the creation of the file if it does not exist
are a single operation that is atomic with respect to all other
filesystem activities that might affect the file.
Note: this method should not be used for file-locking, as
the resulting protocol cannot be made to work reliably. The
FileLock
facility should be used instead.
delete
public boolean delete(
)
Deletes the file or directory denoted by this abstract pathname. If
this pathname denotes a directory, then the directory must be empty in
order to be deleted.
deleteOnExit
public void deleteOnExit(
)
Requests that the file or directory denoted by this abstract
pathname be deleted when the virtual machine terminates.
Deletion will be attempted only for normal termination of the
virtual machine, as defined by the Java Language Specification.
Once deletion has been requested, it is not possible to cancel the
request. This method should therefore be used with care.
Note: this method should not be used for file-locking, as
the resulting protocol cannot be made to work reliably. The
FileLock
facility should be used instead.
equals
public boolean equals(
Object obj
)
Tests this abstract pathname for equality with the given object.
Returns true if and only if the argument is not
null and is an abstract pathname that denotes the same file
or directory as this abstract pathname. Whether or not two abstract
pathnames are equal depends upon the underlying system. On UNIX
systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows
systems it is not.
exists
public boolean exists(
)
Tests whether the file or directory denoted by this abstract pathname
exists.
getAbsoluteFile
public File getAbsoluteFile(
)
Returns the absolute form of this abstract pathname. Equivalent to
new File(this.getAbsolutePath()).
getAbsolutePath
public String getAbsolutePath(
)
Returns the absolute pathname string of this abstract pathname.
If this abstract pathname is already absolute, then the pathname
string is simply returned as if by the getPath
method. If this abstract pathname is the empty abstract pathname then
the pathname string of the current user directory, which is named by the
system property user.dir, is returned. Otherwise this
pathname is resolved in a system-dependent way. On UNIX systems, a
relative pathname is made absolute by resolving it against the current
user directory. On Microsoft Windows systems, a relative pathname is made absolute
by resolving it against the current directory of the drive named by the
pathname, if any; if not, it is resolved against the current user
directory.
getCanonicalFile
public File getCanonicalFile(
)
throws
IOException
Returns the canonical form of this abstract pathname. Equivalent to
new File(this.getCanonicalPath()).
getCanonicalPath
public String getCanonicalPath(
)
throws
IOException
Returns the canonical pathname string of this abstract pathname.
A canonical pathname is both absolute and unique. The precise
definition of canonical form is system-dependent. This method first
converts this pathname to absolute form if necessary, as if by invoking the
getAbsolutePath method, and then maps it to its unique form in a
system-dependent way. This typically involves removing redundant names
such as "." and ".." from the pathname, resolving
symbolic links (on UNIX platforms), and converting drive letters to a
standard case (on Microsoft Windows platforms).
Every pathname that denotes an existing file or directory has a
unique canonical form. Every pathname that denotes a nonexistent file
or directory also has a unique canonical form. The canonical form of
the pathname of a nonexistent file or directory may be different from
the canonical form of the same pathname after the file or directory is
created. Similarly, the canonical form of the pathname of an existing
file or directory may be different from the canonical form of the same
pathname after the file or directory is deleted.
getName
public String getName(
)
Returns the name of the file or directory denoted by this abstract
pathname. This is just the last name in the pathname's name
sequence. If the pathname's name sequence is empty, then the empty
string is returned.
getParent
public String getParent(
)
Returns the pathname string of this abstract pathname's parent, or
null if this pathname does not name a parent directory.
The parent of an abstract pathname consists of the
pathname's prefix, if any, and each name in the pathname's name
sequence except for the last. If the name sequence is empty then
the pathname does not name a parent directory.
getParentFile
public File getParentFile(
)
Returns the abstract pathname of this abstract pathname's parent,
or null if this pathname does not name a parent
directory.
The parent of an abstract pathname consists of the
pathname's prefix, if any, and each name in the pathname's name
sequence except for the last. If the name sequence is empty then
the pathname does not name a parent directory.
getPath
public String getPath(
)
Converts this abstract pathname into a pathname string. The resulting
string uses the character to
separate the names in the name sequence.
hashCode
public int hashCode(
)
Computes a hash code for this abstract pathname. Because equality of
abstract pathnames is inherently system-dependent, so is the computation
of their hash codes. On UNIX systems, the hash code of an abstract
pathname is equal to the exclusive or of its pathname string
and the decimal value 1234321. On Microsoft Windows systems, the hash
code is equal to the exclusive or of its pathname string,
convered to lower case, and the decimal value 1234321.
isAbsolute
public boolean isAbsolute(
)
Tests whether this abstract pathname is absolute. The definition of
absolute pathname is system dependent. On UNIX systems, a pathname is
absolute if its prefix is "/". On Microsoft Windows systems, a
pathname is absolute if its prefix is a drive specifier followed by
"\\", or if its prefix is "\\".
isDirectory
public boolean isDirectory(
)
Tests whether the file denoted by this abstract pathname is a
directory.
isFile
public boolean isFile(
)
Tests whether the file denoted by this abstract pathname 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.
isHidden
public boolean isHidden(
)
Tests whether the file named by this abstract pathname is a hidden
file. The exact definition of hidden is system-dependent. On
UNIX systems, a file is considered to be hidden if its name begins with
a period character ('.'). On Microsoft Windows systems, a file is
considered to be hidden if it has been marked as such in the filesystem.
lastModified
public long lastModified(
)
Returns the time that the file denoted by this abstract pathname was
last modified.
length
public long length(
)
Returns the length of the file denoted by this abstract pathname.
The return value is unspecified if this pathname denotes a directory.
list
public String[] list(
)
Returns an array of strings naming the files and directories in the
directory denoted by this abstract pathname.
If this abstract pathname does not denote a directory, then this
method returns null. Otherwise an array of strings is
returned, one for each file or directory in the directory. Names
denoting the directory itself and the directory's parent directory are
not included in the result. Each string is a file name rather than a
complete path.
There is no guarantee that the name strings in the resulting array
will appear in any specific order; they are not, in particular,
guaranteed to appear in alphabetical order.
list
public String[] list(
FilenameFilter filter
)
Returns an array of strings naming the files and directories in the
directory denoted by this abstract pathname that satisfy the specified
filter. The behavior of this method is the same as that of the
list() method, except that the strings in the
returned array must satisfy the filter. If the given
filter is null then all names are accepted.
Otherwise, a name satisfies the filter if and only if the value
true results when the accept method of the filter is invoked on this
abstract pathname and the name of a file or directory in the directory
that it denotes.
listFiles
public File[] listFiles(
)
Returns an array of abstract pathnames denoting the files in the
directory denoted by this abstract pathname.
If this abstract pathname does not denote a directory, then this
method returns null. Otherwise an array of
File objects is returned, one for each file or directory in
the directory. Pathnames denoting the directory itself and the
directory's parent directory are not included in the result. Each
resulting abstract pathname is constructed from this abstract pathname
using the File(File, String) constructor. Therefore if this pathname
is absolute then each resulting pathname is absolute; if this pathname
is relative then each resulting pathname will be relative to the same
directory.
There is no guarantee that the name strings in the resulting array
will appear in any specific order; they are not, in particular,
guaranteed to appear in alphabetical order.
listFiles
public File[] listFiles(
FileFilter filter
)
Returns an array of abstract pathnames denoting the files and
directories in the directory denoted by this abstract pathname that
satisfy the specified filter. The behavior of this method is the
same as that of the listFiles() method, except
that the pathnames in the returned array must satisfy the filter.
If the given filter is null then all
pathnames are accepted. Otherwise, a pathname satisfies the filter
if and only if the value true results when the
accept(java.io.File) method of
the filter is invoked on the pathname.
listFiles
public File[] listFiles(
FilenameFilter filter
)
Returns an array of abstract pathnames denoting the files and
directories in the directory denoted by this abstract pathname that
satisfy the specified filter. The behavior of this method is the
same as that of the listFiles() method, except
that the pathnames in the returned array must satisfy the filter.
If the given filter is null then all
pathnames are accepted. Otherwise, a pathname satisfies the filter
if and only if the value true results when the
accept method of the filter is
invoked on this abstract pathname and the name of a file or
directory in the directory that it denotes.
mkdir
public boolean mkdir(
)
Creates the directory named by this abstract pathname.
mkdirs
public boolean mkdirs(
)
Creates the directory named by this abstract pathname, including any
necessary but nonexistent parent directories. Note that if this
operation fails it may have succeeded in creating some of the necessary
parent directories.
renameTo
public boolean renameTo(
File dest
)
Renames the file denoted by this abstract pathname.
Whether or not this method can move a file from one filesystem
to another is platform-dependent. The return value should always
be checked to make sure that the rename operation was successful.
setLastModified
public boolean setLastModified(
long time
)
Sets the last-modified time of the file or directory named by this
abstract pathname.
All platforms support file-modification times to the nearest second,
but some provide more precision. The argument will be truncated to fit
the supported precision. If the operation succeeds and no intervening
operations on the file take place, then the next invocation of the
lastModified method will return the (possibly
truncated) time argument that was passed to this method.
setReadOnly
public boolean setReadOnly(
)
Marks the file or directory named by this abstract pathname so that
only read operations are allowed. After invoking this method the file
or directory is guaranteed not to change until it is either deleted or
marked to allow write access. Whether or not a read-only file or
directory may be deleted depends upon the underlying system.
toString
public String toString(
)
Returns the pathname string of this abstract pathname. This is just the
string returned by the getPath method.
toURI
public URI toURI(
)
Constructs a file: URI that represents this abstract pathname.
The exact form of the URI is system-dependent. If it can be
determined that the file denoted by this abstract pathname is a
directory, then the resulting URI will end with a slash.
For a given abstract pathname f, it is guaranteed that
new File( f.toURI()).equals( f.getAbsoluteFile())
so long as the original abstract pathname, the URI, and the new abstract
pathname are all created in (possibly different invocations of) the same
Java virtual machine. Due to the system-dependent nature of abstract
pathnames, however, this relationship typically does not hold when a
file: URI that is created in a virtual machine on one operating
system is converted into an abstract pathname in a virtual machine on a
different operating system.
toURL
public URL toURL(
)
throws
MalformedURLException
Converts this abstract pathname into a file: URL. The
exact form of the URL is system-dependent. If it can be determined that
the file denoted by this abstract pathname is a directory, then the
resulting URL will end with a slash.
Usage note: This method does not automatically escape
characters that are illegal in URLs. It is recommended that new code
convert an abstract pathname into a URL by first converting it into a
URI, via the toURI method, and then converting the URI
into a URL via the URI.toURL method.
|