go to previous page   go to home page   go to next page

Answer:

Class finished!


The main() Method

Since URLscan has potential to be used in other programs, main() should be placed in a separate class. It is responsible for getting the file name from the command line and creating the stream objects BufferedReader and FileReader. Here is a skeletal main():

public class URLextract
{

  public static void main ( String[] args ) throws IOException
  {
    BufferedReader br;
    FileReader     fr;
    String         url;

    if ( args.length != 1 )
    {
      System.out.println("URLextract inputFile");
      System.exit( -1 );
    }

    fr = new  ( args[0] );
    
    br = new  ( fr );

    URLscan scan = new URLscan(  );

    while ( (url = scan.getURL()) !=  )
    {
      System.out.println( url );
    }

    System.out.println("\n\nDone" );

  }

}

Finish the program by filling the blanks.


QUESTION 11:

Will the program work correctly if there are no URLs in the input file?