URL: openStream()


import java.io.InputStream;
import java.net.URL;

public class MainClass {

  public static void main(String args[]) {
    try {

      URL url = new URL("http://www.java2s.com");

      // Obtain output stream
      InputStream is = url.openStream();

      // Read and display data from url
      byte buffer[] = new byte[1024];
      int i;
      while ((i = is.read(buffer)) != -1) {
        System.out.write(buffer, 0, i);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Home 
  Java Book 
    Networking  

URL:
  1. URL
  2. new URL(String spec) throws MalformedURLException
  3. URL: getAuthority()
  4. URL: openConnection()
  5. URL: openStream()