Java Reference
In-Depth Information
Table 8-1 refers to IOException , which is the common exception superclass
for those exception classes that describe various kinds of I/O errors, such as
java.io.FileNotFoundException .
Listing 8-2 instantiates File with its pathname command-line argument, and calls
some of the File methods described in Table 8-1 to learn about this pathname.
Listing 8-2. Obtaining abstract pathname information
import java.io.File;
import java.io.IOException;
class PathnameInfo
{
public static void main(String[] args) throws IOExcep-
tion
{
if (args.length != 1)
{
System.err.println("usage:
java
PathnameInfo
pathname");
return;
}
File file = new File(args[0]);
System.out.println("Absolute
path
=
"+file.getAbsolutePath());
System.out.println("Canonical
path
=
"+file.getCanonicalPath());
System.out.println("Name = "+file.getName());
System.out.println("Parent = "+file.getParent());
System.out.println("Path = "+file.getPath());
System.out.println("Is
absolute
=
"+file.isAbsolute());
 
Search WWH ::




Custom Search