O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading a Web Page via HTTP

URL url = new URL("http://www.timothyfisher.com");
											HttpURLConnection http = new HttpURLConnection(url);
											InputStream in = http.getInputStream();

In this phrase, we go beyond socket level network programming and show you an additional way of reading data from a network. Java supports communication with a URL over HTTP with the HttpURLConnection class. We instantiate a URL instance by passing a valid URL string to the URL constructor. We then instantiate an HttpURLConnection by passing the url instance into the HttpURLConnection constructor. The getInputStream() method is called to get an input stream for reading data from the URL connection. Using the input stream, we could then read the contents of the web page.

You ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required