| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectjava.io.FileField Summary | |
static String |
|
static char |
|
static String |
|
static char |
|
Constructor Summary | |
Method Summary | |
boolean |
|
boolean |
|
boolean |
|
int | |
boolean |
|
static File |
|
static File |
|
boolean |
|
void |
|
boolean | |
boolean |
|
File |
|
String |
|
File |
|
String |
|
String |
|
String |
|
File |
|
String |
|
int |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
long |
|
long |
|
String[] |
|
String[] |
|
File[] |
|
File[] |
|
File[] |
|
static File[] |
|
boolean |
|
boolean |
|
boolean | |
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
String |
|
URI |
|
URL |
|
Methods inherited from class java.lang.Object | |
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait | |
public static final String pathSeparator
This is the string that is used to separate the host name from the path name in paths that include the host name. It is the value of thepath.separatorsystem property.
public static final 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. The separator string is taken from thepath.separatorsystem property.
public static final String separator
This is the path separator string for the current host. This field contains the value of thefile.separatorsystem property. An example separator string would be "/" on the GNU system.
public static final char separatorChar
This is the first character of the file separator string. On many hosts (for example, on the GNU system), this represents the entire separator string. The complete separator string is obtained from thefile.separatorsystem property.
public File(File directory, String name)
This method initializes a newFileobject to represent a file in the specified directory. If thedirectoryargument isnull, the file is assumed to be in the current directory as specified by theuser.dirsystem property
- Parameters:
directory- The directory this file resides inname- The name of the file
public File(String name)
This method initializes a newFileobject to represent a file with the specified path.
- Parameters:
name- The path name of the file
public File(String dirPath, String name)
This method initializes a newFileobject 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.
- Parameters:
dirPath- The path to the directory the file resides inname- The name of the file
public File(URI uri)
This method initializes a newFileobject to represent a file corresponding to the specifiedfile:protocol URI.
- Parameters:
uri- The URI
- Throws:
IllegalArgumentException- if the URI is not hierarchical
public boolean canExecute()
This method tests whether or not the current thread is allowed to to execute the file pointed to by this object. This will be true if and and only if 1) the file exists and 2) theSecurityManager(if any) allows access to the file via it'scheckExecmethod 3) the file is executable.
- Returns:
trueif execution is allowed,falseotherwise
- Throws:
SecurityException- If theSecurityManagerdoes not allow access to the file
public boolean canRead()
This method tests whether or not the current thread is allowed to to read the file pointed to by this object. This will be true if and and only if 1) the file exists and 2) theSecurityManager(if any) allows access to the file via it'scheckReadmethod 3) the file is readable.
- Returns:
trueif reading is allowed,falseotherwise
- Throws:
SecurityException- If theSecurityManagerdoes not allow access to the file
public boolean canWrite()
This method test whether or not the current thread is allowed to write to this object. This will be true if and only if 1) TheSecurityManager(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.
- Returns:
trueif writing is allowed,falseotherwise
- Throws:
SecurityException- If theSecurityManagerdoes not allow access to the file
public int compareTo(File other)
This method compares the specifiedFileto 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 thegetCanonicalPathmethod on each object. This method returns a 0 if the specifiedObjectis equal to this one, a negative value if it is less than this one a positive value if it is greater than this one.
- Returns:
- An integer as described above
- Since:
- 1.2
public boolean createNewFile() throws IOException
This method creates a new file of zero length with the same name as the path of thisFileobject if an only if that file does not already exist. ASecurityManager.checkWritecheck is done prior to performing this action.
- Returns:
trueif the file was created,falseif the file alread existed.
- Throws:
IOException- If an I/O error occursSecurityException- If theSecurityManagerwill not allow this operation to be performed.
- Since:
- 1.2
public static File createTempFile(String prefix, String suffix) throws IOException
This method creates a temporary file in the system temporary directory. The files created are guaranteed not to currently exist and the same file name will never be used twice in the same virtual machine instance. The system temporary directory is determined by examinging thejava.io.tmpdirsystem property. Theprefixparameter is a sequence of at least three characters that are used as the start of the generated filename. Thesuffixparameter is a sequence of characters that is used to terminate the file name. This parameter may benulland if it is, the suffix defaults to ".tmp". If aSecurityManagerexists, then itscheckWritemethod is used to verify that this operation is permitted. This method is identical to callingcreateTempFile(prefix, suffix, null).
- Parameters:
prefix- The character prefix to use in generating the path name.suffix- The character suffix to use in generating the path name.
- Throws:
IllegalArgumentException- If the prefix or suffix are not valid.SecurityException- If there is no permission to perform this operationIOException- If an error occurs
public static File createTempFile(String prefix, String suffix, File directory) throws IOException
This method creates a temporary file in the specified directory. If the directory name is null, then this method uses the system temporary directory. The files created are guaranteed not to currently exist and the same file name will never be used twice in the same virtual machine instance. The system temporary directory is determined by examinging thejava.io.tmpdirsystem property. Theprefixparameter is a sequence of at least three characters that are used as the start of the generated filename. Thesuffixparameter is a sequence of characters that is used to terminate the file name. This parameter may benulland if it is, the suffix defaults to ".tmp". If aSecurityManagerexists, then itscheckWritemethod is used to verify that this operation is permitted.
- Parameters:
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, ornullfor the default temporary directory
- Throws:
IllegalArgumentException- If the patterns is not validSecurityException- If there is no permission to perform this operationIOException- If an error occurs
- Since:
- 1.2
public boolean delete()
This method deletes the file represented by this object. If this file is a directory, it must be empty in order for the delete to succeed.
- Returns:
trueif the file was deleted,falseotherwise
- Throws:
SecurityException- If deleting of the file is not allowed
public void deleteOnExit()
Calling this method requests that the file represented by this object be deleted when the virtual machine exits. Note that this request cannot be cancelled. Also, it will only be carried out if the virtual machine exits normally.
- Throws:
SecurityException- If deleting of the file is not allowed
- Since:
- 1.2
public boolean equals(Object obj)
This method tests twoFileobjects for equality by comparing the path of the specifiedFileagainst the path of this object. The two objects are equal if an only if 1) The argument is not null 2) The argument is aFileobject and 3) The path of theFileargument is equal to the path of this object. The paths of the files are determined by calling thegetPath()method on each object.
- Returns:
trueif the two objects are equal,falseotherwise.
public boolean exists()
This method tests whether or not the file represented by the object actually exists on the filesystem.
- Returns:
trueif the file exists,falseotherwise.
- Throws:
SecurityException- If reading of the file is not permitted
public File getAbsoluteFile()
This method returns aFileobject representing the absolute path of this object.
- Returns:
- A
Filewith the absolute path of the object.
- Since:
- 1.2
public String getAbsolutePath()
This method returns the path of this file as an absolute path name. If the path name is already absolute, then it is returned. Otherwise the value returned is the current directory plus the separatory string plus the path of the file. The current directory is determined from theuser.dirsystem property.
- Returns:
- The absolute path of this file
public File getCanonicalFile() throws IOException
This method returns aFileobject representing the canonical path of this object.
- Returns:
- A
Fileinstance representing the canonical path of this object.
- Throws:
IOException- If an error occurs.
- Since:
- 1.2
public String getCanonicalPath() throws IOException
This method returns a canonical representation of the pathname of this file. The actual form of the canonical representation is system-dependent. On the GNU system, conversion to canonical form involves the removal of redundant separators, references to "." and "..", and symbolic links. 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
- Throws:
IOException- If an error occurs
public String getName()
This method returns the name of the file. This is everything in the complete path of the file after the last instance of the separator string.
- Returns:
- The file name
public String getParent()
This method returns aStringthe represents this file's parent.nullis returned if the file has no parent. The parent is determined via a simple operation which removes the name after the last file separator character, as determined by the platform.
- Returns:
- The parent directory of this file
public File getParentFile()
This method returns aFileobject representing the parent file of this one.
- Returns:
- a
Filefor the parent of this object.nullwill be returned if this object does not have a parent.
- Since:
- 1.2
public String getPath()
Returns the path name that represents this file. May be a relative or an absolute path name
- Returns:
- The pathname of this file
public int hashCode()
This method returns a hash code representing this file. It is the hash code of the path of this file (as returned bygetPath()) exclusived or-ed with the value 1234321.
- Returns:
- The hash code for this object
public boolean isAbsolute()
This method returns true if this object represents an absolute file path and false if it does not. The definition of an absolute path varies by system. As an example, on GNU systems, a path is absolute if it starts with a "/".
- Returns:
trueif this object represents an absolute file name,falseotherwise.
public boolean isDirectory()
This method tests whether or not the file represented by this object is a directory. In order for this method to returntrue, the file represented by this object must exist and be a directory.
- Returns:
trueif this file is a directory,falseotherwise
- Throws:
SecurityException- If reading of the file is not permitted
public boolean isFile()
This method tests whether or not the file represented by this object is a "plain" file. A file is a plain file if and only if it 1) Exists, 2) Is not a directory or other type of special file.
- Returns:
trueif this is a plain file,falseotherwise
- Throws:
SecurityException- If reading of the file is not permitted
public boolean isHidden()
This method tests whether or not this file represents a "hidden" file. On GNU systems, a file is hidden if its name begins with a "." character. Files with these names are traditionally not shown with directory listing tools.
- Returns:
trueif the file is hidden,falseotherwise.
- Since:
- 1.2
public long lastModified()
This method returns the last modification time of this file. The time value returned is an abstract value that should not be interpreted as a specified time value. It is only useful for comparing to other such time values returned on the same system. In that case, the larger value indicates a more recent modification time. If the file does not exist, then a value of 0 is returned.
- Returns:
- The last modification time of the file
- Throws:
SecurityException- If reading of the file is not permitted
public long length()
This method returns the length of the file represented by this object, or 0 if the specified file does not exist.
- Returns:
- The length of the file
- Throws:
SecurityException- If reading of the file is not permitted
public String[] list()
This method returns a array ofString'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, thennullis 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. ASecurityManagercheck is made prior to reading the directory. If read access to the directory is denied, an exception will be thrown.
- Returns:
- An array of files in the directory, or
nullif this object does not represent a valid directory.
- Throws:
SecurityException- If read access is not allowed to the directory by theSecurityManager
public String[] list(FilenameFilter filter)
This method returns a array ofString'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, thennullis 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 thelist()method, a filter is specified that allows the caller to control which files are returned in the list. TheFilenameFilterspecified is called for each file returned to determine whether or not that file should be included in the list. ASecurityManagercheck is made prior to reading the directory. If read access to the directory is denied, an exception will be thrown.
- Parameters:
filter- An object which will identify files to exclude from the directory listing.
- Returns:
- An array of files in the directory, or
nullif this object does not represent a valid directory.
- Throws:
SecurityException- If read access is not allowed to the directory by theSecurityManager
public File[] listFiles()
This method returns an array ofFileobjects representing all the files in the directory represented by this object. If this object does not represent a directory,nullis returned. Each of the returnedFileobject is constructed with this object as its parent. ASecurityManagercheck is made prior to reading the directory. If read access to the directory is denied, an exception will be thrown.
- Returns:
- An array of
Fileobjects for this directory.
- Throws:
SecurityException- If theSecurityManagerdenies access to this directory.
- Since:
- 1.2
public File[] listFiles(FileFilter filter)
This method returns an array ofFileobjects representing all the files in the directory represented by this object. If this object does not represent a directory,nullis returned. Each of the returnedFileobject is constructed with this object as its parent. In this form of thelistFiles()method, a filter is specified that allows the caller to control which files are returned in the list. TheFileFilterspecified is called for each file returned to determine whether or not that file should be included in the list. ASecurityManagercheck is made prior to reading the directory. If read access to the directory is denied, an exception will be thrown.
- Returns:
- An array of
Fileobjects for this directory.
- Throws:
SecurityException- If theSecurityManagerdenies access to this directory.
- Since:
- 1.2
public File[] listFiles(FilenameFilter filter)
This method returns an array ofFileobjects representing all the files in the directory represented by this object. If this object does not represent a directory,nullis returned. Each of the returnedFileobject is constructed with this object as its parent. In this form of thelistFiles()method, a filter is specified that allows the caller to control which files are returned in the list. TheFilenameFilterspecified is called for each file returned to determine whether or not that file should be included in the list. ASecurityManagercheck is made prior to reading the directory. If read access to the directory is denied, an exception will be thrown.
- Returns:
- An array of
Fileobjects for this directory.
- Throws:
SecurityException- If theSecurityManagerdenies access to this directory.
- Since:
- 1.2
public static File[] listRoots()
This method returns an array of filesystem roots. Some operating systems have volume oriented filesystem. This method provides a mechanism for determining which volumes exist. GNU systems use a single hierarchical filesystem, so will have only one "/" filesystem root.
- Returns:
- An array of
Fileobjects for each filesystem root available.
- Since:
- 1.2
public boolean mkdir()
This method creates a directory for the path represented by this object.
- Returns:
trueif the directory was created,falseotherwise
- Throws:
SecurityException- If write access is not allowed to this file
public boolean mkdirs()
This method creates a directory for the path represented by this file. It will also create any intervening parent directories if necessary.
- Returns:
trueif the directory was created,falseotherwise
- Throws:
SecurityException- If write access is not allowed to this file
public boolean renameTo(File dest)
This method renames the file represented by this object to the path of the file represented by the argumentFile.
- Parameters:
dest- TheFileobject representing the target name
- Returns:
trueif the rename succeeds,falseotherwise.
- Throws:
SecurityException- If write access is not allowed to the file by theSecurityMananger.
public boolean setExecutable(boolean executable)
This method sets the owner's execute permission for the File represented by this object. It is the same as callingsetExecutable(readable, true).
- Parameters:
- Returns:
trueif the file permissions are changed,falseotherwise.
- Throws:
SecurityException- If write access of the file is not permitted.
- Since:
- 1.6
- See Also:
setExecutable(boolean,boolean)
public boolean setExecutable(boolean executable, boolean ownerOnly)
This method sets the execute permissions for the File represented by this object. IfownerOnlyis set totruethen only the execute permission bit for the owner of the file is changed. IfownerOnlyis set tofalse, the file permissions are changed so that the file can be executed by everyone. On unix like systems this set theuser,groupandotherwrite bits and is equal to callchmod a+xon the file.
- Parameters:
- Returns:
trueif the file permissions are changed,falseotherwise.
- Throws:
SecurityException- If write access of the file is not permitted.
- Since:
- 1.6
- See Also:
setExecutable(boolean)
public boolean setLastModified(long time)
This method sets the modification time on the file to the specified value. This is specified as the number of seconds since midnight on January 1, 1970 GMT.
- Parameters:
time- The desired modification time.
- Returns:
trueif the operation succeeded,falseotherwise.
- Throws:
IllegalArgumentException- If the specified time is negative.SecurityException- If theSecurityManagerwill not allow this operation.
- Since:
- 1.2
public boolean setReadOnly()
This method sets the file represented by this object to be read only. A read only file or directory cannot be modified. Please note that GNU systems allow read only files to be deleted if the directory it is contained in is writable.
- Returns:
trueif the operation succeeded,falseotherwise.
- Throws:
SecurityException- If theSecurityManagerdoes not allow this operation.
- Since:
- 1.2
public boolean setReadable(boolean readable)
This method sets the owner's read permission for the File represented by this object. It is the same as callingsetReadable(readable, true).
- Parameters:
- Returns:
trueif the file permissions are changed,falseotherwise.
- Throws:
SecurityException- If write access of the file is not permitted.
- Since:
- 1.6
- See Also:
setReadable(boolean,boolean)
public boolean setReadable(boolean readable, boolean ownerOnly)
This method sets the read permissions for the File represented by this object. IfownerOnlyis set totruethen only the read permission bit for the owner of the file is changed. IfownerOnlyis set tofalse, the file permissions are changed so that the file can be read by everyone. On unix like systems this sets theuser,groupandotherread bits and is equal to callchmod a+ron the file.
- Parameters:
- Returns:
trueif the file permissions are changed,falseotherwise.
- Throws:
SecurityException- If write access of the file is not permitted.
- Since:
- 1.6
- See Also:
setReadable(boolean)
public boolean setWritable(boolean writable)
This method sets the owner's write permission for the File represented by this object. It is the same as callingsetWritable(readable, true).
- Parameters:
- Returns:
trueif the file permissions are changed,falseotherwise.
- Throws:
SecurityException- If write access of the file is not permitted.
- Since:
- 1.6
- See Also:
setWritable(boolean,boolean)
public boolean setWritable(boolean writable, boolean ownerOnly)
This method sets the write permissions for the File represented by this object. IfownerOnlyis set totruethen only the write permission bit for the owner of the file is changed. IfownerOnlyis set tofalse, the file permissions are changed so that the file can be written by everyone. On unix like systems this set theuser,groupandotherwrite bits and is equal to callchmod a+won the file.
- Parameters:
- Returns:
trueif the file permissions are changed,falseotherwise.
- Throws:
SecurityException- If write access of the file is not permitted.
- Since:
- 1.6
- See Also:
setWritable(boolean)
public String toString()
This method returns aStringthat is the path name of the file as returned bygetPath.
- Returns:
- A
Stringrepresentation of this file
public URL toURL() throws MalformedURLException
This method returns aURLwith thefile:protocol that represents this file. The exact form of this URL is system dependent.
- Returns:
- A
URLfor this object.
- Throws:
MalformedURLException- If the URL cannot be created successfully.