URL: openStream() : URL « java.net « Java by API






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.new URL(String spec) throws MalformedURLException
2.URL: getAuthority()
3.URL: getDefaultPort()
4.URL.getPath()
5.URL: getQuery()
6.URL: getRef()
7.URL: openConnection()