Read from a URL with buffered stream in Java
Description
The following code shows how to read from a URL with buffered stream.
Example
/* w w w.j a v a2s . c om*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Main {
public static void main(String[] args) throws Exception {
URL u = new URL("http://google.com");
URLConnection uc = u.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String s = br.readLine();
while (s != null) {
System.out.println(s);
s = br.readLine();
}
}
}
The code above generates the following result.