|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.File
public class 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.
Serializable,
Comparable,
Serialized Form| Field Summary | |
|---|---|
static String |
pathSeparator
System dependent path separator String. |
static char |
pathSeparatorChar
System dependent path separator character. |
(package private) byte[] |
properPath
|
static String |
separator
System dependent file separator String. |
static char |
separatorChar
System dependent file separator character. |
| Constructor Summary | |
|---|---|
File(File dir,
String name)
Constructs a new File using the specified directory and name. |
|
File(String path)
Constructs a new File using the specified path. |
|
File(String dirPath,
String name)
Constructs a new File using the specified directory and name placing a path separator between the two. |
|
File(URI uri)
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. |
|
| Method Summary | |
|---|---|
boolean |
canRead()
Returns a boolean indicating whether or not the current context is allowed to read this File. |
boolean |
canWrite()
Returns a boolean indicating whether or not the current context is allowed to write to this File. |
int |
compareTo(File another)
Returns the relative sort ordering of paths for the receiver and given argument. |
boolean |
createNewFile()
Creates the file specified by this File. |
static File |
createTempFile(String prefix,
String suffix)
Creates an empty temporary file using the given prefix and suffix as part of the file name. |
static File |
createTempFile(String prefix,
String suffix,
File directory)
Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name. |
boolean |
delete()
Deletes the file specified by this File. |
void |
deleteOnExit()
When the virtual machine terminates, any abstract files which have been sent deleteOnExit() will be deleted. |
boolean |
equals(Object obj)
Compares the argument obj to the receiver, and returns
true if they represent the same object using a
path specific comparison. |
boolean |
exists()
Returns a boolean indicating whether or not this File can be found on the underlying file system. |
File |
getAbsoluteFile()
Returns a new File constructed using the absolute file path of this File. |
String |
getAbsolutePath()
Returns the absolute file path of this File. |
File |
getCanonicalFile()
Returns a new File created using the canonical file path of this File. |
String |
getCanonicalPath()
Returns the absolute file path of this File with all references resolved. |
String |
getName()
Returns the filename (not directory) of this File. |
String |
getParent()
Returns the pathname of the parent of this File. |
File |
getParentFile()
Returns a new File made from the pathname of the parent of this File. |
String |
getPath()
Returns the file path of this File. |
int |
hashCode()
Returns an integer hash code for the receiver. |
boolean |
isAbsolute()
Returns if this File is an absolute pathname. |
boolean |
isDirectory()
Returns if this File represents a directory on the underlying file system. |
boolean |
isFile()
Returns if this File represents a file on the underlying file system. |
boolean |
isHidden()
Returns whether or not this file is a hidden file as defined by the operating system. |
long |
lastModified()
Returns the time this File was last modified. |
long |
length()
Returns the length of this File in bytes. |
String[] |
list()
Returns an array of Strings representing the file names in the directory represented by this File. |
String[] |
list(FilenameFilter filter)
Returns an array of Strings representing the file names in the directory represented by this File that match a specific filter. |
File[] |
listFiles()
Returns an array of Files representing the file names in the directory represented by this File. |
File[] |
listFiles(FileFilter filter)
Returns an array of Files representing the file names in the directory represented by this File that match a specific filter. |
File[] |
listFiles(FilenameFilter filter)
Returns an array of Files representing the file names in the directory represented by this File that match a specific filter. |
static File[] |
listRoots()
Lists the filesystem roots. |
boolean |
mkdir()
Creates the directory named by the trailing filename of this File. |
boolean |
mkdirs()
Create all the directories needed for this File. |
(package private) byte[] |
properPath(boolean internal)
Answer a String representing the proper path for the receiver. |
boolean |
renameTo(File dest)
Renames this File to the name represented by the File dest. |
boolean |
setLastModified(long time)
Sets the time this File was last modified. |
boolean |
setReadOnly()
Marks this file or directory to be read-only as defined by the operating system. |
String |
toString()
Returns a string containing a concise, human-readable description of the receiver. |
URI |
toURI()
Returns a file URI for this File. |
URL |
toURL()
Returns a file URL for this File. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
transient byte[] properPath
public static final char separatorChar
public static final String separator
public static final char pathSeparatorChar
public static final String pathSeparator
| Constructor Detail |
|---|
public File(File dir,
String name)
dir - the directory for the file namename - the file name to be contained in the dirpublic File(String path)
path - the path to be used for the file
public File(String dirPath,
String name)
dirPath - the directory for the file namename - the file name to be contained in the dirpublic File(URI 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.toURI(),
URI| Method Detail |
|---|
public static File[] listRoots()
public boolean canRead()
true if this File can be read, false
otherwise.SecurityManager.checkRead(FileDescriptor)public boolean canWrite()
true if this File can be written,
false otherwise.SecurityManager.checkWrite(FileDescriptor)public int compareTo(File another)
compareTo in interface Comparable<File>another - a File to compare the receiver to
Comparablepublic boolean delete()
true if this File was deleted, false
otherwise.
SecurityException - in case a SecurityManager
is installed, and it denies the request.SecurityManager.checkDelete(java.lang.String)public void deleteOnExit()
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.public boolean equals(Object obj)
obj to the receiver, and returns
true if they represent the same object using a
path specific comparison.
equals in class Objectobj - the Object to compare with this Object
true if the object is the same as this object,
false otherwise.Object.hashCode()public boolean exists()
true if this File exists, false
otherwise.getPath(),
SecurityManager.checkRead(FileDescriptor)public String getAbsolutePath()
SecurityManager.checkPropertyAccess(java.lang.String)public File getAbsoluteFile()
SecurityManager.checkPropertyAccess(java.lang.String)
public String getCanonicalPath()
throws IOException
IOException - if an IO error occursSecurityManager.checkPropertyAccess(java.lang.String)
public File getCanonicalFile()
throws IOException
new File(this.getCanonicalPath()).
IOException - If an IO error occursSecurityManager.checkPropertyAccess(java.lang.String)public String getName()
public String getParent()
null is returned when
there is no parent.
nullpublic File getParentFile()
null
is returned when there is no parent.
nullpublic String getPath()
public int hashCode()
true when passed to equals must
answer the same value for this method.
hashCode in class Objectequals(java.lang.Object)public boolean isAbsolute()
true if this File is absolute, false
otherwise.getPath()public boolean isDirectory()
true if this File is a directory,
false otherwise.getPath(),
SecurityManager.checkRead(FileDescriptor)public boolean isFile()
true if this File is a file, false
otherwise.getPath(),
SecurityManager.checkRead(FileDescriptor)public boolean isHidden()
true if the file is hidden, false
otherwise.public long lastModified()
getPath(),
SecurityManager.checkRead(FileDescriptor)public boolean setLastModified(long time)
time - The time to set the file as last modified.
SecurityManager.checkWrite(FileDescriptor)public boolean setReadOnly()
true if the operation was a success,
false otherwisepublic long length()
getPath(),
SecurityManager.checkRead(FileDescriptor)public String[] list()
null.
The entries . and .. representing current
directory and parent directory are not returned as part of the list.
null.getPath(),
isDirectory(),
SecurityManager.checkRead(FileDescriptor)public File[] listFiles()
null. The Files returned will be absolute if this File is
absolute, relative otherwise.
null.getPath(),
list(),
isDirectory()public File[] listFiles(FilenameFilter filter)
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.list(FilenameFilter filter),
getPath(),
isDirectory(),
SecurityManager.checkRead(FileDescriptor)public File[] listFiles(FileFilter filter)
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.getPath(),
isDirectory(),
SecurityManager.checkRead(FileDescriptor)public String[] list(FilenameFilter filter)
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.getPath(),
isDirectory(),
SecurityManager.checkRead(FileDescriptor)public boolean mkdir()
true if the directory was created,
false otherwise.getPath(),
SecurityManager.checkWrite(FileDescriptor)public boolean mkdirs()
true.
true if the necessary directories were created,
false otherwise.
public boolean createNewFile()
throws IOException
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.SecurityManager.checkWrite(FileDescriptor)
public static File createTempFile(String prefix,
String suffix)
throws IOException
.tmp is used.
prefix - the prefix to the temp file namesuffix - the suffix to the temp file name
IOException - If an error occurs when writing the file
public static File createTempFile(String prefix,
String suffix,
File directory)
throws IOException
prefix - the prefix to the temp file namesuffix - the suffix to the temp file namedirectory - 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 filebyte[] properPath(boolean internal)
internal - is user.dir internal
public boolean renameTo(File dest)
dest.
This works for both normal files and directories.
dest - the File containing the new name.
true if the File was renamed, false
otherwise.getPath(),
SecurityManager.checkRead(FileDescriptor),
SecurityManager.checkWrite(FileDescriptor)public String toString()
toString in class Objectpublic URI toURI()
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.
public URL toURL()
throws MalformedURLException
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
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||