import java.io.*;

/**
 * This class takes a parameter on the command line, and prints the file
 * given to standard out.  If con is taken as the parameter, it duplicates
 * standard input.
 * This also demonstrates the use of BufferedReaders and System.in
 * Press Ctl-Z to send it the end of file marker and terminate the program.
 *
 * @author JJ Johns
 **/

public class cat2 {

    public static void main(String[] args) {

	// read from the standard input stream, System.in

	if (args[0].equals("con")) {

	    BufferedReader reader;
	    reader = new BufferedReader(new InputStreamReader( System.in ));

	    String line = null;

	    try {

			while ((line = reader.readLine())!= null) {
			    System.out.println(line);
			}

	    } catch (IOException ioe) { ioe.printStackTrace(); }
	}



	else {

	    BufferedReader reader = null;

		try {
		    reader = new BufferedReader(new FileReader(args[0]));
		}
		catch(ArrayIndexOutOfBoundsException aeo) {
		    System.out.println("Usage: java cat FILENAME");
		    System.exit(0);
		}
		catch(FileNotFoundException fnfe) {
		    System.out.println("File named " + args[0] + " was not found.");
		    System.exit(0);
		}


	    String line = null;

	    try {
			while ((line = reader.readLine())!= null) {
			    System.out.println(line);
			}

	    } catch (IOException ioe) { ioe.printStackTrace(); }
	}

    }
}
