| java.lang.Object | |
| ↳ | java.io.File |
File is a class which represents a file name or directory. The file may be absolute relative to the root directory of the file system or relative to the current directory in which the program is running.
This class provides methods for querying/changing information about the file and also directory listing capabilities if the File represents a directory.
When manipulating file paths, the static fields of this class may be used to determine the platform specific separators.
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | pathSeparator | System dependent path separator String. | |||||||||
| char | pathSeparatorChar | System dependent path separator character. | |||||||||
| String | separator | System dependent file separator String. | |||||||||
| char | separatorChar | System dependent file separator character. | |||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new File using the specified directory and name.
| |||||||||||
Constructs a new File using the specified path.
| |||||||||||
Constructs a new File using the specified directory and name placing a
path separator between the two.
| |||||||||||
Constructs a new File using the path of the specified URI
uri needs to be an absolute and hierarchical
URI with file scheme, and non-empty path component, but
with undefined authority, query or fragment components. | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Returns a boolean indicating whether or not the current context is
allowed to read this File.
| |||||||||||
Returns a boolean indicating whether or not the current context is
allowed to write to this File.
| |||||||||||
Returns the relative sort ordering of paths for the receiver and given
argument.
| |||||||||||
Creates the file specified by this File.
| |||||||||||
Creates an empty temporary file in the given directory using the given
prefix and suffix as part of the file name.
| |||||||||||
Creates an empty temporary file using the given prefix and suffix as part
of the file name.
| |||||||||||
Deletes the file specified by this File.
| |||||||||||
When the virtual machine terminates, any abstract files which have been
sent
deleteOnExit() will be deleted. | |||||||||||
Compares the argument
obj to the receiver, and returns
true if they represent the same object using a
path specific comparison. | |||||||||||
Returns a boolean indicating whether or not this File can be found on the
underlying file system.
| |||||||||||
Returns a new File constructed using the absolute file path of this File.
| |||||||||||
Returns the absolute file path of this File.
| |||||||||||
Returns a new File created using the canonical file path of this File.
| |||||||||||
Returns the absolute file path of this File with all references resolved.
| |||||||||||
Returns the filename (not directory) of this File.
| |||||||||||
Returns the pathname of the parent of this File.
| |||||||||||
Returns a new File made from the pathname of the parent of this File.
| |||||||||||
Returns the file path of this File.
| |||||||||||
Returns an integer hash code for the receiver.
| |||||||||||
Returns if this File is an absolute pathname.
| |||||||||||
Returns if this File represents a directory on the underlying
file system.
| |||||||||||
Returns if this File represents a file on the underlying file
system.
| |||||||||||
Returns whether or not this file is a hidden file as defined by the
operating system.
| |||||||||||
Returns the time this File was last modified.
| |||||||||||
Returns the length of this File in bytes.
| |||||||||||
Returns an array of Strings representing the file names in the directory
represented by this File.
| |||||||||||
Returns an array of Strings representing the file names in the directory
represented by this File that match a specific filter.
| |||||||||||
Returns an array of Files representing the file names in the directory
represented by this File that match a specific filter.
| |||||||||||
Returns an array of Files representing the file names in the directory
represented by this File that match a specific filter.
| |||||||||||
Returns an array of Files representing the file names in the directory
represented by this File.
| |||||||||||
Lists the filesystem roots.
| |||||||||||
Creates the directory named by the trailing filename of this File.
| |||||||||||
Create all the directories needed for this File.
| |||||||||||
Renames this File to the name represented by the File
dest. | |||||||||||
Sets the time this File was last modified.
| |||||||||||
Marks this file or directory to be read-only as defined by the operating
system.
| |||||||||||
Returns a string containing a concise, human-readable description of the
receiver.
| |||||||||||
Returns a
file URI for this File. | |||||||||||
Returns a
file URL for this File. | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface java.lang.Comparable
| |||||||||||
System dependent path separator String. The initial value of this field is the System property "path.separator".
System dependent path separator character.
System dependent file separator String. The initial value of this field is the System property "file.separator".
System dependent file separator character.
Constructs a new File using the specified directory and name.
| dir | the directory for the file name |
|---|---|
| name | the file name to be contained in the dir |
Constructs a new File using the specified path.
| path | the path to be used for the file |
|---|
Constructs a new File using the specified directory and name placing a path separator between the two.
| dirPath | the directory for the file name |
|---|---|
| name | the file name to be contained in the dir |
Constructs a new File using the path of the specified URI
uri needs to be an absolute and hierarchical
URI with file scheme, and non-empty path component, but
with undefined authority, query or fragment components.
| uri | the URI instance which will be used to construct this file |
|---|
| IllegalArgumentException | if uri does not comply with the conditions
above. |
|---|
Returns a boolean indicating whether or not the current context is allowed to read this File.
true if this File can be read, false
otherwise.Returns a boolean indicating whether or not the current context is allowed to write to this File.
true if this File can be written,
false otherwise.Returns the relative sort ordering of paths for the receiver and given argument. The ordering is platform dependent.
| another | a File to compare the receiver to |
|---|
Creates the file specified by this File. If the file already exists this
method returns false. Otherwise, if the file is created
successfully, the result is true. An IOException will be
thrown if the directory to contain this file does not exist.
true if this File was created, false
otherwise.| IOException | if an I/O error occurs or the directory does not exist. |
|---|
Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.
| prefix | the prefix to the temp file name |
|---|---|
| suffix | the suffix to the temp file name |
| directory | the location to which the temp file is to be written, or null for the default temp location |
| IOException | If an error occurs when writing the file |
|---|
Creates an empty temporary file using the given prefix and suffix as part
of the file name. If suffix is null, .tmp is used.
| prefix | the prefix to the temp file name |
|---|---|
| suffix | the suffix to the temp file name |
| IOException | If an error occurs when writing the file |
|---|
Deletes the file specified by this File. Directories must be empty before they will be deleted.
true if this File was deleted, false
otherwise.| SecurityException | in case a SecurityManager
is installed, and it denies the request. |
|---|
When the virtual machine terminates, any abstract files which have been
sent deleteOnExit() will be deleted. This will only happen
when the virtual machine terminates normally as described by the Java
Language Specification section 12.9.
| SecurityException | in case a SecurityManager
is installed, and it denies the request.
|
|---|
Compares the argument obj to the receiver, and returns
true if they represent the same object using a
path specific comparison.
| obj | the Object to compare with this Object |
|---|
true if the object is the same as this object,
false otherwise.
Returns a boolean indicating whether or not this File can be found on the underlying file system.
true if this File exists, false
otherwise.Returns a new File constructed using the absolute file path of this File.
Returns the absolute file path of this File.
Returns a new File created using the canonical file path of this File.
Equivalent to new File(this.getCanonicalPath()).
| IOException | If an IO error occurs |
|---|
Returns the absolute file path of this File with all references resolved. An absolute file path is one which begins at the root of the file system. The canonical path is one in which all references have been resolved. For the cases of '..' and '.' where the file system supports parent and working directory respectively, these should be removed and replaced with a direct directory reference. If the File does not exist, getCanonicalPath() may not resolve any references and simply return an absolute path name or throw an IOException.
| IOException | if an IO error occurs |
|---|
Returns the filename (not directory) of this File.
Returns the pathname of the parent of this File. This is the path up to
but not including the last name. null is returned when
there is no parent.
null
Returns a new File made from the pathname of the parent of this File.
This is the path up to but not including the last name. null
is returned when there is no parent.
null
Returns the file path of this File.
Returns an integer hash code for the receiver. Any two objects which
answer true when passed to equals must
answer the same value for this method.
Returns if this File is an absolute pathname. Whether a pathname is absolute is platform specific. On UNIX it is if the path starts with the character '/', on Windows it is absolute if either it starts with '\', '/', '\\' (to represent a file server), or a letter followed by a colon.
true if this File is absolute, false
otherwise.Returns if this File represents a directory on the underlying file system.
true if this File is a directory,
false otherwise.Returns if this File represents a file on the underlying file system.
true if this File is a file, false
otherwise.Returns whether or not this file is a hidden file as defined by the operating system.
true if the file is hidden, false
otherwise.
Returns the time this File was last modified.
Returns the length of this File in bytes.
Returns an array of Strings representing the file names in the directory
represented by this File. If this File is not a directory the result is
null.
The entries . and .. representing current
directory and parent directory are not returned as part of the list.
null.Returns an array of Strings representing the file names in the directory
represented by this File that match a specific filter. If this File is
not a directory the result is null. If the filter is
null then all filenames match.
The entries . and .. representing current
directory and parent directory are not returned as part of the list.
| filter | the filter to match names to or null. |
|---|
null.Returns an array of Files representing the file names in the directory
represented by this File that match a specific filter. If this File is
not a directory the result is null. If the filter is
null then all filenames match.
The entries . and .. representing current
directory and parent directory are not returned as part of the list.
| filter | the filter to match names to or null. |
|---|
null.Returns an array of Files representing the file names in the directory
represented by this File that match a specific filter. If this File is
not a directory the result is null. If the filter is
null then all filenames match.
The entries . and .. representing current
directory and parent directory are not returned as part of the list.
| filter | the filter to match names to or null. |
|---|
null.Returns an array of Files representing the file names in the directory
represented by this File. If this File is not a directory the result is
null. The Files returned will be absolute if this File is
absolute, relative otherwise.
null.Lists the filesystem roots. The Java platform may support zero or more filesystems, each with its own platform-dependent root. Further, the canonical pathname of any file on the system will always begin with one of the returned filesystem roots.
Creates the directory named by the trailing filename of this File. Not all directories required to create this File are created.
true if the directory was created,
false otherwise.Create all the directories needed for this File. If the terminal
directory already exists, answer false. If the directories were created
successfully, answer true.
true if the necessary directories were created,
false otherwise.
Renames this File to the name represented by the File dest.
This works for both normal files and directories.
| dest | the File containing the new name. |
|---|
true if the File was renamed, false
otherwise.Sets the time this File was last modified.
| time | The time to set the file as last modified. |
|---|
Marks this file or directory to be read-only as defined by the operating system.
true if the operation was a success,
false otherwise
Returns a string containing a concise, human-readable description of the receiver.
Returns a file URI for this File. The URI is System
dependent and may not be transferable between different operating/file
systems.
file URI for this File.
Returns a file URL for this File. The URL is System
dependent and may not be transferable between different operating/file
systems.
file URL for this File.| MalformedURLException | if the path cannot be transformed into an URL |
|---|