URL.openStream() has the following syntax.
public final InputStream openStream() throws IOException
In the following code shows how to use URL.openStream() method.
//from www . j a v a2 s . 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.