11 : The java.io Package
Write code that uses objects of
the file class to navigate a file system.
class extends Object, implements Comparable,
Serializable. The current user directory is named by
the system property user.dir, and is usually the
directory in which the JVM was invoked. File is an
abstract representation of file and directory path
names. Instances of this class are immutable.
system dependent path separator character, represented
as a string for convenience. This string contains a
single character, namely pathSeparatorChar.
system dependent default name separator character,
represented as a string for convenience. This string
contains a single character, namely separatorChar.
parent is null then the new file instance is created
as if by invoking File(String pathname). Otherwise,
the parent abstract pathname is taken to denote a
directory, and child is taken either as a directory or
NullPointerException if child is null.
NullPointerException if pathname is null.
other object is an abstract pathname, then this method
behaves as the previous method, otherwise
ClassCastException is thrown.
Atomically creates a new, empty file named by this
abstract pathname if and only if a file with this name
does not exist yet. Returns false if the named file
this file or directory. If it is a directory, then the
directory must be empty in order to be deleted.
that file be deleted when JVM terminates. Once the
request has been made, it is not possible to cancel
null if this pathname does not name a parent
File getParentFile ()
String getPath ()
this abstract pathname to
a pathname string.
boolean isAbsolute ()
boolean isHidden ()
long lastModified ()
zero if the file does not exist or if an I/O error
long length ()
String  list ()
file object does not denote a directory then this and
the following method return null. Names denoting the
directory itself and the directory’s parent directory
are not included in the result. Each string is a file
name rather than a complete path.
file object does not denote a directory then this
method returns null. If this pathname is absolute then
each resulting pathname is absolute; if this pathname
is relative then each resulting pathname will be
relative to the same directory.
the directory named by this abstract pathname,
including any necessary but non existent parent
directories. If this operation fails, it may have
succeeded in creating some of the necessary parent
directories. Returns true only if the directory, along
with all necessary parent directories was created;
SecurityException. Throws NullPointerException if
destination is null.
IllegalArgumentException if n is negative.
boolean setReadOnly ()
URL toURL ()
this object into a file:URL. Throws MalformedException
if the path cannot be passed as a URL.
section11-1 | section11-2 | section11-3 | section11-4 | section11-5 | section11-6
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11