Consider the following code:
/************************************************************** WebPageReader.java* Dean&Dean** This reads a web page through a buffer.*************************************************************/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 WebPageReaderUse this program as a starting point and make these adjustments to it:
• Add
importstatements as required.• 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
throwsclause.Within a generic catch block in
main,catch any exception and print its class and message usinggetClassandgetMessagemethod calls.
Be 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.educlass java.net.MalformedURLException
unknown protocol: htp
Second sample session:
Enter a full URL address: http:/www.park.educlass java.lang.IllegalArgumentException
protocol = http host = null
Third sample session:
Enter a full URL address: http://www.park.edu
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.