13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

96Chapter 3An Experienced Programmer’s Introducti<strong>on</strong> to JavaExample 3.30 Single class example: FetchURLimport java.net.*;import java.io.*;public class FetchURL {private URL requestedURL;public FetchURL(String urlName){try {requestedURL = new URL(urlName);} catch (Excepti<strong>on</strong> e) {e.printStackTrace();}}public String toString(){String rc = "";String line;BufferedReader rdr;try {rdr = new BufferedReader(new InputStreamReader(requestedURL.openC<strong>on</strong>necti<strong>on</strong>().getInputStream()));while ((line = rdr.readLine()) != null){rc = rc + line + "\n";}} catch (Excepti<strong>on</strong> e) {e.printStackTrace();rc = null;}}return rc;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!