Java Reference
In-Depth Information
File
objects are created with one of four constructors:
public
File(String path)
Creates a
File
object to manipulate the specified
path
.
public
File(String dirName, String name)
Creates a
File
object for the file
name
in the directory named
dirName
. If
dirName
is
null
, only
name
is used. If
dirName
is an
empty string,
name
is resolved against a system dependent
default directory.
Otherwise,
this is equivalent
to using
File(dirName + File.separator + name)
.
public
File(File fileDir, String name)
Creates a
File
object for the file
name
in the directory named
by
the
object
fileDir
.
Equivalent
to
using
File
File(fileDir.getPath(), name)
.
public
File(java.net.URI uri)
Creates a
File
object for the pathname represented by the
given
file: URI
(Uniform Resource Identifier). If the given
URI
is not a suitable file
URI
then
IllegalArgumentException
is
thrown.
Five "get" methods retrieve information about the components of a
File
object's pathname. The following code invokes each of them after cre-
ating a
File
object for the file
"FileInfo.java"
in the
"ok"
subdirectory of
the parent of the current directory (specified by
".."
):
File src = new File(".." + File.separator + "ok",
"FileInfo.java");
System.out.println("getName() = " + src.getName());
System.out.println("getPath() = " + src.getPath());
System.out.println("getAbsolutePath() = "