URL: openStream()
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();
}
}
}