Mega Code Archive

 
Categories / Java / Network Protocol
 

URL Get

import java.io.*; import java.net.*; public class URLGet {   public static void main(String[] args) {     BufferedReader in=null;     if (args.length == 1) {       try {         URL url = new URL(args[0]);         in = new BufferedReader(new InputStreamReader(url.openStream()));         String line=null;         while ((line=in.readLine()) != null)           System.out.println(line);       }       catch (MalformedURLException ex) {         System.err.println(ex);       }       catch (FileNotFoundException ex) {         System.err.println("Failed to open stream to URL: "+ex);       }       catch (IOException ex) {         System.err.println("Error reading URL content: "+ex);       }       if (in != null)         try {in.close();} catch (IOException ex) {}     }     else       System.err.println ("Usage: URLGet URL");   } }