URL: openStream() : URL : java.net : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP
Java by API Home »  java.net   » [  URL  ]   
 



URL: openStream()

/*
 * Output:
 *  
 */

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();
    }
  }
}
           
       
Related examples in the same category
1.  URL: getAuthority()
2.  URL: getDefaultPort()
3.  URL.getPath()
4.  URL: getQuery()
5.  URL: getRef()
























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