Java Reference
In-Depth Information
16.
URL urlToRead = null ;
17.
try {
18.
urlToRead = new URL(urlName);
19.
}
20.
catch (Exception ex) {
21.
ex.printStackTrace();
22.
}
23.
// Read and the URL characterwise
24.
// and print it to the console.
25.
if (urlToRead != null ){
26.
try {// Open the streams
27.
InputStream inputStream = urlToRead.openStream();
28.
int c=inputStream.read();
29.
while (c != -1) {
30.
System.out.print(( char )c);
31.
c=inputStream.read();
32.
}
33.
inputStream.close();
34.
} catch (Exception e){System.out.println("Problem reading from URL");}
35.
}
36.
}
37. }
The source code of the web page that appears on the console looks like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="Winedit 2000">
<META NAME="Author" CONTENT="Paul Fischer">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000"
ALINK="#FF00FF" BACKGROUND="?">
<H1> TEST HTML-Document</H1>
This is the first page.
<p>
<A HREF="test2.html">Link to the next page</A>.
</BODY>
</HTML>
Search WWH ::




Custom Search