/** * Title: ListFiles * Description: Uses File objects to print a recursive list of * files/directories * @author hollingd@cs.rpi.edu */ import java.io.*; class ListFiles { public static void main(String [] args ) { File f; try { f = new File(args[0]); // print info about the file with indentation "" Print(f,""); } catch (Exception e) { System.out.println("Invalid usage"); e.printStackTrace(); } } // prints information about a file or directory // for files: shows the name and size // for directories, shows the name and a list of everything // inside the directory (recursively). // indent is used to make the directory list look // like and indented (outline mode) list static public void Print(File f,String indent) { if (f.isFile() ) { // it's a file System.out.println(indent + f.getName()+ " (" + f.length() + " bytes)"); } else if (f.isDirectory()) { // it's a directory System.out.println(indent + f.getName() + " (is a directory)"); File[] sublist = f.listFiles(); for (int i=0;i