Java URL.openStream()
Syntax
URL.openStream() has the following syntax.
public final InputStream openStream() throws IOException
Example
In the following code shows how to use URL.openStream() method.
//from www . j av a 2s .c o m
import java.io.DataInputStream;
import java.net.URL;
public class Main {
public static void main (String[] args) throws Exception {
String thisLine;
URL u = new URL("http://www.google.com");
DataInputStream theHTML = new DataInputStream(u.openStream());
while ((thisLine = theHTML.readLine()) != null) {
System.out.println(thisLine);
}
}
}
The code above generates the following result.