import java.io.*;
import java.net.*;

/**
 * An example that illustrates the flexibility of I/O streams
 * in Java
 *
 * -k              To use the keyboard
 * -f filename     To use a file (e.g., cs.txt)
 * -u url          To use a URL  (e.g., http://www.cs.jmu.edu/common/coursedocs/BernsteinMaterials/javaexamples/iobasics/cs.txt)
 */
public class ReaderExample
{
    /**
     * The entry point of the application
     *
     * @param args   The command-line arguments
     */
    public static void main(String[] args) throws IOException
    {
	BufferedReader       in;
	FileReader           fileReader;
	InputStreamReader    isReader;
	PrintWriter          out;
	String               line;
	URL                  url;


	in = null;

	// Construct the appropriate kind of BufferedReader based
	// on the command-line options
	if (args[0].equals("-f")) {         // Read from a file

	    fileReader = new FileReader(args[1]);
	    in = new BufferedReader(fileReader);

	} else if (args[0].equals("-u")) { // Read from a URL

	    url = new URL(args[1]);
	    isReader = new InputStreamReader(url.openStream());
            in = new BufferedReader(isReader);

	} else {                         // Read from the keyboard

	    isReader = new InputStreamReader(System.in);
	    in = new BufferedReader(isReader);
	}


	out = new PrintWriter(System.out);

	// Keep reading and printing until EOF
	do {

	    line = in.readLine();
	    if (line != null) {
		out.println(line);
		out.flush();
	    }

	} while (line != null);
    }




}
