Java Reference
In-Depth Information
Double
This is a wrapper class for
double
. See Section 5.1 in Chapter 5 .
File
Package:
java.io
Ancestor classes:
Object
|
+--File
Many of these methods throw a
SecurityException
if a security manager exists and is
unhappy with the method invocation. This is not likely to be a concern for readers of this topic,
and we have not noted this in the method descriptions.
The class
SecurityException
is an unchecked exception class, which means you need not
catch it or declare it in a
throws
clause.
public
File(String fileName)
Constructor.
fileName
can be either a full or a relative pathname (which includes the case of a
simple fi le name).
fileName
is referred to as the
abstract pathname
.
Throws:
NullPointerException
if the pathname
fileName
is
null
.
public boolean
canRead()
Tests whether the program can read from the fi le. Returns
true
if the fi le named by the abstract
pathname exists and is readable by the program; otherwise returns
false
.
public boolean
canWrite()
Tests whether the program can write to the fi le. Returns
true
if the fi le named by the abstract
pathname exists and is writable by the program; otherwise returns
false
.
public boolean
createNewFile()
Creates a new empty fi le named by the abstract pathname, provided that a fi le of that name
does not already exist. Returns
true
if successful; returns
false
otherwise.
Throws:
IOException
if an I/O error occurs.
public boolean
delete( )
Tries to delete the fi le or directory named by the abstract pathname. A directory must be empty
to be removed. Returns
true
if it was able to delete the fi le or directory. Returns
false
if it was
unable to delete the fi le or directory.
public boolean
exists()
Tests whether there is a fi le with the abstract pathname.