Java Reference
In-Depth Information
However, files are usually created by
FileOutputStream
or
FileWriter
ob-
jects or
RandomAccessFile
objects, not using
File
objects.
Two methods let you change the state of the underlying file, assuming
that one exists:
public boolean
setLastModified(long time)
Sets the "last modified" time for the file or returns
false
if it
cannot do so.
public boolean
setReadOnly()
Makes the underlying file unmodifiable in the file system or
returns
false
if it cannot do so. The file remains unmodifiable
until it is deleted or externally marked as modifiable again-
there is no method for making it modifiable again.
There are methods for listing the contents of directories and finding out
about root directories:
public String[]
list()
Lists the files in this directory. If used on something that isn't
a directory, it returns
null
. Otherwise, it returns an array of
file names. This list includes all files in the directory except
the equivalent of
"."
and
".."
(the current and parent direct-
ory, respectively).
public String[]
list(FilenameFilter filter)
Uses
filter
to selectively list files in this directory (see
File-
nameFilter
described in the next section).
public static File[]
listRoots()