001package edu.pdx.cs410J.net; 002 003import java.io.*; 004import java.net.*; 005 006/** 007 * This program dumps the contents of a URL to standard out. 008 */ 009public class DumpURL { 010 private static PrintStream err = System.err; 011 012 /** 013 * Read the URL from the command line. 014 */ 015 public static void main(String[] args) { 016 URL url = null; 017 try { 018 url = new URL(args[0]); 019 020 } catch (MalformedURLException ex) { 021 err.println("** Bad URL: " + args[0]); 022 System.exit(1); 023 } 024 025 try { 026 InputStream urlStream = url.openStream(); 027 InputStreamReader isr = new InputStreamReader(urlStream); 028 BufferedReader br = new BufferedReader(isr); 029 030 while (br.ready()) { 031 String line = br.readLine(); 032 System.out.println(line); 033 } 034 035 br.close(); 036 037 } catch (IOException ex) { 038 err.println("** IOException: " + ex); 039 System.exit(1); 040 } 041 } 042 043}