import java.io.*;
import java.util.Scanner;

/**
 * Reads the file given by the command line argument and prints its contents,
 * line by line, to the screen.
 *
 * @author Zach Tomaszewski
 * @version 19 Nov 2009
 */
public class FileViewer {

  public static void main(String[] args) {
    if (args.length == 0) {
        //incorrect usage, so give usage message
        System.out.println("No filename specified on command line.\n");
        System.out.println("Usage: java FileViewer filename\n");
        System.out.println("This program prints the contents of the given " +
                           "file to the screen.");
    }else {
      try {
        Scanner filein = new Scanner(new File(args[0]));
        while (filein.hasNextLine()) {
          System.out.println(filein.nextLine());
        }
      }catch (FileNotFoundException fnfe) {
        System.out.println("Could not open file: " + fnfe.getMessage());
      }
    }
  }

}
