WebPageReader program:
In addition to testing your exception handling prowess, this exercise also tests your ability to use online help and/or reference books. The following program attempts to read in a Web address and print the contents of the Web page at that address.
In the given program:
For each class that’s used, add an
import statement for it, if it’s necessary.For each method call and constructor call:
If it throws an unchecked exception, ignore it.
If it throws a checked exception:
Specify the specific exception in a
throws clause.Within a
catch block inmain , catch the exception and print the exception’s message using itsgetMessage method.
Assume that the following code works except for the items mentioned above.
/************************************************************** WebPageReader.java* Dean & Dean** This reads a Web page.*************************************************************/import java.util.Scanner;public class WebPageReader{BufferedReader reader;public WebPageReader(String webAddress){URL url = new URL(webAddress);URLConnection connection = url.openConnection();InputStream in = connection.getInputStream();reader = new BufferedReader(new InputStreamReader(in));} // end constructor//**********************************************************public String readLine(){return reader.readLine();} // end readLine//**********************************************************public static void main(String[] args){Scanner stdIn = new Scanner(System.in);String url, line;System.out.print("Enter a full URL address: ");url = stdIn.nextLine();WebPageReader wpr = new WebPageReader(url);while ((line = wpr.readLine()) != null){System.out.println(line);}} // end main} // end WebPageReaderBe aware that your program might be correct, but it might not be able to access Web pages successfully. To access Web pages, your computer needs to have Internet access capabilities. If your firewall asks if it’s OK for Java to access the Internet, click “yes” and continue. Here are three sample sessions:
First sample session:
Enter a full URL address: htp://www.park.eduunknown protocol: htpSecond sample session:
Enter a full URL address: http:/www.park.eduConnection refused: connectThird sample session:
Enter a full URL address: http://www.park.eduPark University Home Page . . .
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.