Page 631 - Introduction to Programming with Java: A Problem Solving Approach
P. 631

                }
// end WebPageReader
}
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)
{
}
// end main
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)
{
}
Apago PDF Enhancer
System.out.println(line);
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.edu
unknown protocol: htp
Second sample session:
Enter a full URL address: http:/www.park.edu
Connection refused: connect
Third sample session:
Enter a full URL address: http://www.park.edu
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Park University Home Page</title>
<meta name="TITLE" content="Park University Home Page:
Exercises 597
   Bachelor's, Master's and Online Degree Programs" />






















































   629   630   631   632   633