Java Reference
In-Depth Information
The java.io.File class (continued)
{
System.out.println(file.getName()
+ “ can be read from.”);
}
if(file.isDirectory())
{
System.out.println(file.getPath()
+ “ is a directory containing...”);
String [] files = file.list();
for(int i = 0; i < files.length; i++)
{
System.out.println(files[i]);
}
}
}
}
Figure 16.1 shows a sample output of running the FileDemo program when an actual
file is used as the command-line argument. Figure 16.2 shows the output when the
command-line argument is a valid directory.
Figure 16.1
The command-line argument is a file that exists.
Figure 16.2
The FileDemo program lists the contents of the given directory.
Search WWH ::




Custom Search