jeffheaton's picture

    In this chapter you learned how to perform basic HTTP operations with Java. You saw how you can access a URL and download the contents of that URL.

    Java contains a URL class. This class allows you to open connections to a URL. By calling the openStream function on a URL object, you are given an InputStream object that you can use to access the contents of the URL. Once you have an InputStream, you can read from the URL essentially the same as if you were reading from a file.

    You were shown that downloading to a binary file means making an exact copy of the incoming data and is preferred when downloading images, audio, and other binary data. Downloading a text file requires you to translate the incoming line breaks to the correct format for your operating system.

    In this chapter you saw how to use the URL and InputStream classes to access web pages. This is fine for simple requests; however for more complex requests you will need to use the HttpURLConnection class. This class will be introduced in the next chapter.


Copyright 2005 - 2012 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright, license and trademark information.