Java BufferedReader read from URL

Description

Java BufferedReader read from URL

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;// w  ww  .  j  a  va  2  s  .com
    while ((line = in.readLine()) != null) {
      System.out.println(line);
    }
    in.close();
  }
}



PreviousNext

Related