import java.net.*;
import java.io.*;

// A pure 1.1 variation of a utility that appears in
// Core Web Programming from Prentice Hall Publishers.
// May be freely used or adapted.
// 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/.

/** Read a remote file using the standard URL class
 *  instead of connecting explicitly to the HTTP server.
 */

public class UrlRetriever2 {
  public static void main(String[] args) {
    checkUsage(args);
    try {
      URL url = new URL(args[0]);
      BufferedReader in =
        new BufferedReader(
             new InputStreamReader(
               url.openStream()));
      String line;
      while ((line = in.readLine()) != null)
        System.out.println("> " + line);
      in.close();
    } catch(MalformedURLException mue) { // URL c'tor
      System.out.println(args[0] + "is an invalid URL: "
                         + mue);
    } catch(IOException ioe) { // Stream constructors
      System.out.println("IOException: " + ioe);
    }
  }

  private static void checkUsage(String[] args) {
    if (args.length != 1) {
      System.out.println("Usage: UrlRetriever2 <URL>");
      System.exit(-1);
    }
  }
}

