[an error occurred while processing this directive]
Domain for sale!
Start Search Contents Index Links About
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 GetPageURL theURL )
  {
    BufferedReader bufReader;
    String line;
    
    try
    {
      //open file
      bufReader = new BufferedReadernew InputStreamReader(theURL.openStream()) );
      
      //read line by line
      while( (line = bufReader.readLine()) != null )
      {
        //output to screen
        System.out.printlnline );
      }
      
      //close the file when finished
      bufReader.close();
    }
    catchIOException e )
    {
      System.out.println"GetPage.GetPage - error opening or reading URL: " + e );
    }
  }
  
  
  public static void mainString 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
}


site: Håvard Rast Blok
mail:
updated: 16 July 2010