Java URL open stream for reading

Description

Java URL open stream for reading

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {

  public static void main(String[] args) throws Exception {
    URL url = new URL("https://demo2s.com");
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;/*from w w w . j  a  va2  s. c  o m*/
    while ((line = in.readLine()) != null) {
      System.out.println(line);
    }
    in.close();
  }
}



PreviousNext

Related