 |
|
|
GetPage.java
|
/*
* Author: Havard Rast Blok
* E-mail: 
* Web : www.rememberjava.com
*/
import java.io.*;
import java.net.*;
/**
* This small application takes an URL as argument, downloads that
* web page and outputs it to the screen.
*
* Refer to the main() method for how to read a local file instead.
*/
public class GetPage
{
public GetPage( URL theURL )
{
BufferedReader bufReader;
String line;
try
{
//open file
bufReader = new BufferedReader( new InputStreamReader(theURL.openStream()) );
//read line by line
while( (line = bufReader.readLine()) != null )
{
//output to screen
System.out.println( line );
}
//close the file when finished
bufReader.close();
}
catch( IOException e )
{
System.out.println( "GetPage.GetPage - error opening or reading URL: " + e );
}
}
public static void main( String args[] )
{
try
{
new GetPage(new URL(args[0]));
//Open file from disk instead
//File f = new File( args[0] );
//new GetPage( f.toURL() );
}
catch (MalformedURLException e)
{
System.out.println("GetPage.main - wrong url: " +e );
}
}// end main
}
|
|
|
 |