import java.net.*; import java.io.*; /** URLReader2 reads lines from a URL given on the command line Copied from: http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html on 01/17/2012. @version for CS56, W12 @author P.Conrad with help from oracle.com */ public class URLReader2 { public static void main(String[] args) throws Exception { if (args.length!=1) { System.err.println("Error: need URL on command line"); System.exit(1); } URL cs = null; try { cs = new URL(args[0]); } catch ( java.net.MalformedURLException mue ) { System.err.println("Oops " + mue); System.exit(1); } BufferedReader in = new BufferedReader( new InputStreamReader( cs.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } }