Class java.io.File
All Packages This Package Previous Next
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.
-
Version:
-
1.24, 13 Feb 1995
-
Author:
-
Jonathan Payne,
Arthur van Hoff
-
path
-
The path of the file.
-
separator
-
Separator string.
-
separatorChar
-
Separator character.
-
File(String)
-
Creates a File object.
-
File(String, String)
-
Creates a File object (given a directory).
-
File(File, String)
-
Creates a File object (given a directory File object).
-
canRead()
-
Returns true if the file exists and is readable.
-
canWrite()
-
Returns true if the file exists and is writable.
-
equals(Object)
-
Compares this object against some other object.
-
exists()
-
Returns true if the 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.
-
getReadACL()
-
Get the value of the read ACL.
-
getWriteACL()
-
Gets the value of the write ACL.
-
hashCode()
-
Computes a hashcode for the file.
-
isAbsolute()
-
Returns true if the file name is absolute.
-
isDirectory()
-
Returns true if the file exists and is a directory.
-
isFile()
-
Returns true if the file exists and is a normal file.
-
lastModified()
-
Returns last modification time.
-
list()
-
Lists the files in a directory.
-
list(FilenameFilter)
-
Lists the files in a directory Use the filter to select
which files.
-
mkdir()
-
Create a directory.
-
mkdirs()
-
Creates all directories in this path.
-
renameTo(File)
-
Rename a file.
-
setAccessErrorHandler(AccessErrorHandler)
-
Initializes the handler object which will get invoked if an
incorrect access is attempted.
-
setExecACL(String)
-
Initializes security ACL for executing files.
-
setReadACL(String)
-
Initializes security ACL for reading files.
-
setWriteACL(String)
-
Initializes security ACL for writing files.
-
toString()
-
Converts to a string.
path
protected String path
-
The path of the file. The host's file separator is used.
separator
public final static String separator
-
Separator string. System dependent.
separatorChar
public final static char separatorChar
-
Separator character. System dependent.
File
public File(String path)
-
Creates a File object.
-
Parameters:
-
path
-
file path
File
public File(String path,
String name)
-
Creates a File object (given a directory).
-
Parameters:
-
path
-
directory
-
name
-
file name
File
public File(File dir,
String name)
-
Creates a File object (given a directory File object).
-
Parameters:
-
dir
-
the directory
-
name
-
file name
getName
public String getName()
-
Gets the name of the file. Not including the
directory.
getPath
public String getPath()
-
Gets the path of the file.
getAbsolutePath
public String getAbsolutePath()
-
Gets the absolute path of the file.
getParent
public String getParent()
-
Gets the name of the parent directory.
-
Returns:
-
the parent directory, or null if there isn't one
exists
public boolean exists()
-
Returns true if the file exists.
canWrite
public boolean canWrite()
-
Returns true if the file exists and is writable.
canRead
public boolean canRead()
-
Returns true if the file exists and is readable.
isFile
public boolean isFile()
-
Returns true if the file exists and is a normal file.
isDirectory
public boolean isDirectory()
-
Returns true if the file exists and is a directory.
isAbsolute
public boolean isAbsolute()
-
Returns true if the file name is absolute.
lastModified
public int lastModified()
-
Returns last modification time. The return value should
only be used to compare modifications dates. It is meaningless
as an absolute time.
mkdir
public boolean mkdir()
-
Create a directory.
-
Returns:
-
true if successfull
renameTo
public boolean renameTo(File dest)
-
Rename a file.
-
Returns:
-
true if successfull
mkdirs
public boolean mkdirs()
-
Creates all directories in this path.
list
public String list()
-
Lists the files in a directory. Works only works 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)
-
Lists the files in a directory Use the filter to select
which files.
-
Parameters:
-
filter
-
the filter used to select file names
-
See Also:
-
FilenameFilter
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 some other object.
-
Parameters:
-
obj
-
the object to compare with
-
Returns:
-
true if the object is the same
-
Overrides:
-
equals in class Object
toString
public String toString()
-
Converts to a string.
-
Overrides:
-
toString in class Object
setReadACL
public static void setReadACL(String path)
-
Initializes security ACL for reading files.
Can only be executed once.
-
Parameters:
-
path
-
a list of directories separated by ':'s.
getReadACL
public static String getReadACL()
-
Get the value of the read ACL.
setWriteACL
public static void setWriteACL(String path)
-
Initializes security ACL for writing files.
Can only be executed once.
-
Parameters:
-
path
-
a list of directories separated by ':'s.
getWriteACL
public static String getWriteACL()
-
Gets the value of the write ACL.
setExecACL
public static void setExecACL(String path)
-
Initializes security ACL for executing files.
Can only be executed once.
-
Parameters:
-
path
-
a list of directories separated by ':'s.
setAccessErrorHandler
public static void setAccessErrorHandler(AccessErrorHandler h)
-
Initializes the handler object which will get invoked if an
incorrect access is attempted. The handler can override the
acl. This method can only be invoked once.
-
See Also:
-
AccessErrorHandler
All Packages This Package Previous Next