James
2012-11-29 17:38:12 UTC
/**
* @(#)URLReader.java
* @
* @ version 1.00 2012/11/29
*/
// http://www.gutenberg.org/files/1399/1399-8.txt
import java.net.*;
import java.io.*;
public class URLReader
{
public static void main(String[] args) throws Exception
{
// Open a connection to the URL, and get an input stream for reading data from the URL.
String Gutenberg = "http://www.gutenberg.org/files/1399/1399-8.txt";
URL url = new URL(Gutenberg);
System.out.println("Reading URL: " + url);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
System.out.println();
// Copy lines of text from the input stream to the screen, until "end-of-file" is encountered
// (or an error occurs).
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}