![]() |
|
Contents |
Inherited by PlatformFile.
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.
java.lang.Comparable
Public Member Functions | |
| 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. | |
| boolean | canRead () |
| Answers a boolean indicating whether or not the current context is allowed to read this File. | |
| boolean | canWrite () |
| Answers a boolean indicating whether or not the current context is allowed to write to this File. | |
| int | compareTo (File another) |
| Answers the relative sort ordering of paths for the receiver and given argument. | |
| 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 answers true if they represent the same object using a path specific comparison. | |
| boolean | exists () |
| Answers a boolean indicating whether or not this File can be found on the underlying file system. | |
| String | getAbsolutePath () |
| Answers the absolute file path of this File. | |
| File | getAbsoluteFile () |
| Answers a new File constructed using the absolute file path of this File. | |
| String | getCanonicalPath () throws IOException |
| Answers the absolute file path of this File with all references resolved. | |
| File | getCanonicalFile () throws IOException |
| Answers a new File created using the canonical file path of this File. | |
| String | getName () |
| Answers the filename (not directory) of this File. | |
| String | getParent () |
| Answers the pathname of the parent of this File. | |
| File | getParentFile () |
| Answers a new File made from the pathname of the parent of this File. | |
| String | getPath () |
| Answers the file path of this File. | |
| int | hashCode () |
| Answers an integer hash code for the receiver. | |
| boolean | isAbsolute () |
| Answers if this File is an absolute pathname. | |
| boolean | isDirectory () |
| Answers if this File represents a directory on the underlying file system. | |
| boolean | isFile () |
| Answers 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 () |
| Answers the time this File was last modified. | |
| 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. | |
| long | length () |
| Answers the length of this File in bytes. | |
| String[] | list () |
| Answers an array of Strings representing the file names in the directory represented by this File. | |
| File[] | listFiles () |
| Answers an array of Files representing the file names in the directory represented by this File. | |
| File[] | listFiles (FilenameFilter filter) |
| Answers an array of Files representing the file names in the directory represented by this File that match a specific filter. | |
| File[] | listFiles (FileFilter filter) |
| Answers an array of Files representing the file names in the directory represented by this File that match a specific filter. | |
| String[] | list (FilenameFilter filter) |
| Answers an array of Strings representing the file names in the directory represented by this File that match a specific filter. | |
| boolean | mkdir () |
| Creates the directory named by the trailing filename of this File. | |
| boolean | mkdirs () |
| Create all the directories needed for this File. | |
| boolean | createNewFile () throws IOException |
| Creates the file specified by this File. | |
| boolean | renameTo (File dest) |
Renames this File to the name represented by the File dest. | |
| String | toString () |
| Answers a string containing a concise, human-readable description of the receiver. | |
| URI | toURI () |
Answers a file URI for this File. | |
| URL | toURL () throws java.net.MalformedURLException |
Answers a file URL for this File. | |
Static Public Member Functions | |
| static File[] | listRoots () |
| Lists the filesystem roots. | |
| static File | createTempFile (String prefix, String suffix) throws IOException |
| 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) throws IOException |
| Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name. | |
Static Public Attributes | |
| static final char | separatorChar |
| System dependent file separator character. | |
| static final String | separator |
| System dependent file separator String. | |
| static final char | pathSeparatorChar |
| System dependent path separator character. | |
| static final String | pathSeparator |
| System dependent path separator String. | |
Static Package Functions | |
| [static initializer] | |
Private Member Functions | |
| void | checkURI (URI uri) |
| boolean | isHidden0 (String path) |
| long | lastModified0 (String path) |
| boolean | setLastModified0 (String path, long time) |
| boolean | setReadOnly0 (String path) |
| long | length0 (String filePath) |
| boolean | mkdir0 (String path) |
| boolean | newFile0 (String path) throws IOException |
| boolean | rename0 (String pathExist, String pathNew) |
| String | getAbsoluteName () |
| void | writeObject (ObjectOutputStream stream) throws IOException |
| void | readObject (ObjectInputStream stream) throws IOException, ClassNotFoundException |
| FileSystemInfo | getFileSystemInfo (String path) |
| FileSystemInfo | getFileSystemInfoForDirectory (String path) |
| FileSystemInfo | getFileSystemInfoForFile (String path) |
| boolean | delete0 (String path) |
| String | fixSlashes (String origPath) |
| The purpose of this method is to take a path and fix the slashes up. | |
Static Private Member Functions | |
| static synchronized String[] | list0 (String absPath) |
| static File | genTempFile (String prefix, String suffix, File directory) |
| static boolean | isCaseSensitive () |
Private Attributes | |
| String | path |
| String | absPath |
Static Private Attributes | |
| static final long | serialVersionUID = 301077366599181567L |
| static final String | EMPTY_STRING = "" |
| static int | counter |
| static boolean | caseSensitive |
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 |
| File | ( | String | path | ) |
| File | ( | String | dirPath, | |
| String | name | |||
| ) |
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. |
| [static initializer] | ( | ) | [static, package] |
| void checkURI | ( | URI | uri | ) | [private] |
| static File [] listRoots | ( | ) | [static] |
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.
| boolean canRead | ( | ) |
| boolean canWrite | ( | ) |
| int compareTo | ( | File | another | ) |
Answers 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 |
| boolean delete | ( | ) |
| void deleteOnExit | ( | ) |
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.
| boolean equals | ( | Object | obj | ) |
Compares the argument obj to the receiver, and answers 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. | boolean exists | ( | ) |
| String getAbsolutePath | ( | ) |
| File getAbsoluteFile | ( | ) |
| String getCanonicalPath | ( | ) | throws IOException |
Answers 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 |
| File getCanonicalFile | ( | ) | throws IOException |
Answers a new File created using the canonical file path of this File.
Equivalent to new File(this.getCanonicalPath()).
| IOException | If an IO error occurs |
| String getName | ( | ) |
| String getParent | ( | ) |
Answers 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 | File getParentFile | ( | ) |
| String getPath | ( | ) |
| int hashCode | ( | ) |
Answers 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.
| boolean isAbsolute | ( | ) |
Answers 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.| boolean isDirectory | ( | ) |
| boolean isFile | ( | ) |
| boolean isHidden | ( | ) |
Returns whether or not this file is a hidden file as defined by the operating system.
true if the file is hidden, false otherwise. Reimplemented in WinFile, and PlatformFile.
| boolean isHidden0 | ( | String | path | ) | [private] |
| long lastModified | ( | ) |
| long lastModified0 | ( | String | path | ) | [private] |
| boolean setLastModified | ( | long | time | ) |
| boolean setLastModified0 | ( | String | path, | |
| long | time | |||
| ) | [private] |
| boolean setReadOnly | ( | ) |
Marks this file or directory to be read-only as defined by the operating system.
true if the operation was a success, false otherwise | boolean setReadOnly0 | ( | String | path | ) | [private] |
| long length | ( | ) |
| long length0 | ( | String | filePath | ) | [private] |
| String [] list | ( | ) |
| File [] listFiles | ( | ) |
Answers 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.Reimplemented in WinFile.
| File [] listFiles | ( | FilenameFilter | filter | ) |
Answers 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.| File [] listFiles | ( | FileFilter | filter | ) |
Answers 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.| String [] list | ( | FilenameFilter | filter | ) |
Answers 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.| static synchronized String [] list0 | ( | String | absPath | ) | [static, private] |
| boolean mkdir | ( | ) |
| boolean mkdir0 | ( | String | path | ) | [private] |
| boolean mkdirs | ( | ) |
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. | boolean createNewFile | ( | ) | throws IOException |
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. |
| boolean newFile0 | ( | String | path | ) | throws IOException [private] |
| static File createTempFile | ( | String | prefix, | |
| String | suffix | |||
| ) | throws IOException [static] |
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 |
| static File createTempFile | ( | String | prefix, | |
| String | suffix, | |||
| File | directory | |||
| ) | throws IOException [static] |
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 |
| boolean renameTo | ( | File | dest | ) |
| boolean rename0 | ( | String | pathExist, | |
| String | pathNew | |||
| ) | [private] |
| String toString | ( | ) |
Answers a string containing a concise, human-readable description of the receiver.
Reimplemented in WinFile.
| URI toURI | ( | ) |
| URL toURL | ( | ) | throws java.net.MalformedURLException |
Answers 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.| java.net.MalformedURLException | if the path cannot be transformed into an URL |
| String getAbsoluteName | ( | ) | [private] |
| void writeObject | ( | ObjectOutputStream | stream | ) | throws IOException [private] |
| void readObject | ( | ObjectInputStream | stream | ) | throws IOException, ClassNotFoundException [private] |
| FileSystemInfo getFileSystemInfo | ( | String | path | ) | [private] |
| FileSystemInfo getFileSystemInfoForDirectory | ( | String | path | ) | [private] |
| FileSystemInfo getFileSystemInfoForFile | ( | String | path | ) | [private] |
| boolean delete0 | ( | String | path | ) | [private] |
| static boolean isCaseSensitive | ( | ) | [static, private] |
| String fixSlashes | ( | String | origPath | ) | [private] |
The purpose of this method is to take a path and fix the slashes up.
This includes changing them all to the current platforms fileSeparator and removing duplicates.
final long serialVersionUID = 301077366599181567L [static, private] |
final String EMPTY_STRING = "" [static, private] |
String path [private] |
String absPath [private] |
final char separatorChar [static] |
System dependent file separator character.
final String separator [static] |
System dependent file separator String.
The initial value of this field is the System property "file.separator".
final char pathSeparatorChar [static] |
System dependent path separator character.
final String pathSeparator [static] |
System dependent path separator String.
The initial value of this field is the System property "path.separator".
int counter [static, private] |
boolean caseSensitive [static, private] |