import java.io.*;

/**
 * List.java
 * <br>A class to demnstrate File I/O
 * <br>
 * Created: Fri Feb  7 08:08:52 2003
 *
 * @author <a href="mailto:shapiro@cse.buffalo.edu">Stuart C. Shapiro</a>
 */

public class List {
    
    /**
     * Lists a file on System.out<br>
     * The file name must be supplied as a command-line argument.
     * <br>
     * Prints an appropriate message if the file doesn't exist.
     * <br> Prints an appropriate message if there is an I/O error during operation.
     *
     * @param args a <code>String[]</code> value
     * <br>
     * arg[0] is used as the name of the file to be printed.
     * <br>
     * Other command-line arguments are ignored.
     */
    public static void main (String[] args) {

	String filename = "";
	String input;

	try {
	    filename = args[0];
	} catch (ArrayIndexOutOfBoundsException e) {
	    System.out.println("A file name must be supplied.");
	    System.exit(1);
	} // end of try-cach

	try {
	    BufferedReader reader =
		new BufferedReader(new FileReader(filename));
	    System.out.println(filename);
	    for (int i = 0; i < filename.length(); i++) {
		System.out.print("=");
	    } // end of for
	    System.out.println();

	    while ( (input = reader.readLine()) != null ) {
		System.out.println(input);
	    } // end of while
	    reader.close();

	} catch (FileNotFoundException e) {
	    System.out.println("File \"" + filename + "\" not found.");
	} catch (IOException e) {
	    System.out.println("I/O error.");
	} // end of try-catch

    } // end of main ()
    
}// List
