Java Reference
In-Depth Information
Returns the file length in bytes, or zero if the file does not ex-
ist.
public boolean
renameTo(File newName)
Renames the file, returning
true
if the rename succeeded.
public boolean
delete()
Deletes the file or directory named in this
File
object, return-
ing
true
if the deletion succeeded. Directories must be empty
before they are deleted.
There are methods to create an underlying file or directory named by
the current
File
:
public boolean
createNewFile()
Creates a new empty file, named by this
File
. Returns
false
if the file already exists or if the file cannot be created. The
check for the existence of the file and its subsequent creation
is performed atomically with respect to other file system op-
erations.
public boolean
mkdir()
Creates a directory named by this
File
, returning
TRue
on suc-
cess.
public boolean
mkdirs()
Creates all directories in the path named by this
File
, return-
ing
TRue
if all were created. This is a way to ensure that a
particular directory is created, even if it means creating other
directories that don't currently exist above it in the directory
hierarchy. Note that some of the directories may have been
created even if
false
is returned.