Following code snippet prints contents of a web page, character by character.
String str = "http://www.java.forums.org";
try {
URL u = new URL(str);
URLConnection uc = u.openConnection( );
InputStream raw = uc.getInputStream( );
InputStream buffer = new BufferedInputStream(raw);
Reader r = new InputStreamReader(buffer);
int c;
while ((c = r.read( )) != -1) {
System.out.print((char) c);
}
}
catch (MalformedURLException ex) {
System.err.println(str + " is not a parseable URL");
}
catch (IOException ex) {
System.err.println(ex);
}