Class java.io.File
All Packages Class Hierarchy This Package Previous Next Index
Class java.io.File
java.lang.Object
|
+----java.io.File
- public class File
- extends Object
This class represents a file name of the host file system.
The file name can be relative or absolute. It must use
the file name conventions of the host platform.
The intention is to provide an abstraction that deals
with most of the system-dependent file name features such
as the separator character, root, device name, etc.
Not all features are currently fully implemented.
Note that whenever a file name or path is used it is
assumed that the host's file name conventions are used.
-
pathSeparator
- The system dependent path separator string.
-
pathSeparatorChar
- The system dependent path separator character.
-
separator
- The system dependent file separator String.
-
separatorChar
- The system dependent file separator character.
-
File(String)
- Creates a File object.
-
File(String, String)
- Creates a File object from the specified directory.
-
File(File, String)
- Creates a File object (given a directory File object).
-
canRead()
- Returns a boolean indicating whether or not a readable file
exists.
-
canWrite()
- Returns a boolean indicating whether or not a writable file
exists.
-
delete()
- Deletes the specified file.
-
equals(Object)
- Compares this object against the specified object.
-
exists()
- Returns a boolean indicating whether or not a file exists.
-
getAbsolutePath()
- Gets the absolute path of the file.
-
getName()
- Gets the name of the file.
-
getParent()
- Gets the name of the parent directory.
-
getPath()
- Gets the path of the file.
-
hashCode()
- Computes a hashcode for the file.
-
isAbsolute()
- Returns a boolean indicating if the file name is absolute.
-
isDirectory()
- Returns a boolean indicating whether or not a directory file
exists.
-
isFile()
- Returns a boolean indicating whether or not a normal file
exists.
-
lastModified()
- Returns the last modification time.
-
length()
- Returns the length of the file.
-
list()
- Lists the files in a directory.
-
list(FilenameFilter)
- Uses the specified filter to list files in a directory.
-
mkdir()
- Creates a directory and returns a boolean indicating the
success of the creation.
-
mkdirs()
- Creates all directories in this path.
-
renameTo(File)
- Renames a file and returns a boolean indicating whether
or not this method was successful.
-
toString()
- Returns a String object representing this file's path.
separator
public final static String separator
- The system dependent file separator String.
separatorChar
public final static char separatorChar
- The system dependent file separator character.
pathSeparator
public final static String pathSeparator
- The system dependent path separator string.
pathSeparatorChar
public final static char pathSeparatorChar
- The system dependent path separator character.
File
public File(String path)
- Creates a File object.
- Parameters:
- path - the file path
- Throws: NullPointerException
- If the file path is equal to
null.
File
public File(String path,
String name)
- Creates a File object from the specified directory.
- Parameters:
- path - the directory path
- name - the file name
File
public File(File dir,
String name)
- Creates a File object (given a directory File object).
- Parameters:
- dir - the directory
- name - the file name
getName
public String getName()
- Gets the name of the file. This method does not include the
directory.
- Returns:
- the file name.
getPath
public String getPath()
- Gets the path of the file.
- Returns:
- the file path.
getAbsolutePath
public String getAbsolutePath()
- Gets the absolute path of the file.
- Returns:
- the absolute file path.
getParent
public String getParent()
- Gets the name of the parent directory.
- Returns:
- the parent directory, or null if one is not found.
exists
public boolean exists()
- Returns a boolean indicating whether or not a file exists.
canWrite
public boolean canWrite()
- Returns a boolean indicating whether or not a writable file
exists.
canRead
public boolean canRead()
- Returns a boolean indicating whether or not a readable file
exists.
isFile
public boolean isFile()
- Returns a boolean indicating whether or not a normal file
exists.
isDirectory
public boolean isDirectory()
- Returns a boolean indicating whether or not a directory file
exists.
isAbsolute
public boolean isAbsolute()
- Returns a boolean indicating if the file name is absolute.
lastModified
public long lastModified()
- Returns the last modification time. The return value should
only be used to compare modification dates. It is meaningless
as an absolute time.
length
public long length()
- Returns the length of the file.
mkdir
public boolean mkdir()
- Creates a directory and returns a boolean indicating the
success of the creation.
renameTo
public boolean renameTo(File dest)
- Renames a file and returns a boolean indicating whether
or not this method was successful.
- Parameters:
- dest - the new file name
mkdirs
public boolean mkdirs()
- Creates all directories in this path. This method
returns true if all directories in this path are created.
list
public String[] list()
- Lists the files in a directory. Works only on directories.
- Returns:
- an array of file names. This list will include all
files in the directory except the equivalent of "." and ".." .
list
public String[] list(FilenameFilter filter)
- Uses the specified filter to list files in a directory.
- Parameters:
- filter - the filter used to select file names
- Returns:
- the filter selected files in this directory.
- See Also:
- FilenameFilter
delete
public boolean delete()
- Deletes the specified file. Returns true
if the file could be deleted.
hashCode
public int hashCode()
- Computes a hashcode for the file.
- Overrides:
- hashCode in class Object
equals
public boolean equals(Object obj)
- Compares this object against the specified object.
- Parameters:
- obj - the object to compare with
- Returns:
- true if the objects are the same; false otherwise.
- Overrides:
- equals in class Object
toString
public String toString()
- Returns a String object representing this file's path.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index