Software >> Development >> Languages >> Java >> examples >> URLReader.java

/* */ import java.net.*; import java.io.*; /* * This example illustrates using a URL to access resources * on a secure site. * * If you are running inside a firewall, please also set the following * Java system properties to the appropriate value: * * http.proxyHost = <proxy server hostname> * http.proxyPort = <proxy server port> * * https.proxyHost = <secure proxy server hostname> * https.proxyPort = <secure proxy server port> */ public class URLReader { public static void main(String[] args) throws Exception { String inputLine; String urlstring; urlstring=""; if (args.length < 1) { System.out.println( "USAGE: java URLReader " + "URL"); System.exit(-1); } try { urlstring = args[0]; } catch (IllegalArgumentException e) { System.out.println("USAGE: java URLReader " + "URL"); System.exit(-1); } URL myurl = new URL(urlstring); BufferedReader in = new BufferedReader( new InputStreamReader( myurl.openStream())); while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } }