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 ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.