//FileViewer.java

import java.io.*;

/**
 * A program that prints a file to the screen.
 * 
 * @author Zach Tomaszewski
 * @version 16 Sept 2004
 */
public class FileViewer {

  /**
   * Prints the contents of the file named in the first command line
   * argument.
   *
   * @param args  Command line arguments
   */
  public static void main(String[] args) {
    if (args.length != 1) {
      System.out.println("\nFileViewer prints the contents of a text " +
                         "file to the screen.");
      System.out.println("\nUsage: java FileViewer {filename}\n");
    }else {
      try{
        FileViewer fv = new FileViewer();
        fv.showFile(args[0]);
      }catch (IOException ioe) {
        System.out.println("Could not open or read file: " + args[0]);
      }
    }
  }

  /**
   * Opens the given file and prints its contents to the screen.
   * The file must be a text (character) file.
   *
   * @param filename  The file to open and display
   */
  public void showFile(String filename) throws IOException {
    BufferedReader filein = new BufferedReader(new FileReader(filename));
    String nextLine = filein.readLine();
    while (nextLine != null){
      System.out.println(nextLine);
      nextLine = filein.readLine();
    }
    filein.close();
  }
}
