URL Get : URL : Network Protocol : Java examples (example source code) Organized by topic

Java
C++
Java Home »  Network Protocol   » [  URL  ]  Screenshots 
 



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");
  }
}

           
       
Related examples in the same category
1.  URL Constructor Test
2.  URL Encode Test
3.  Get URL Content
4.  Get URL Parts
5.  Read from a URL
6.  URL Equality
7.  URL Request
8.  URL Reader
9.  URL Connection Reader URL Connection Reader
10.  URLConnection
11.  Parse URL Parse URL








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.