/* Punters Lounge JAVA programming course * * Lesson9.java * * Author : Erik Datapunter * Date : 18 july 2004 * * Downloads the course introduction thread, count the number of posts by datapunter * */ // import the libraries with the Input / Output objects and the networking objects import java.net.*; import java.io.*; // our program called ReadPage.java public class Lesson9 { // our main method, the words throws Exception are required as part of the error handling public static void main(String[ ] arguments) throws Exception { // a String variable to hold a line read from the web page String aline; // creation of a URL object containing the address of the web page we want to read URL webadres = new URL("http://p076.ezboard.com/fpuntersloungefrm57.showMessage?topicID=119.topic"); // creation of a BufferedReader object to hold the info read from the web page BufferedReader Readpage = new BufferedReader(new InputStreamReader(webadres.openStream())); /* while we are able to read lines from the page * * the method readLine() from the BufferedReader object is used * to read a line from the webpage, that line is stored in the aline variable */ int DP = 0; while ((aline = Readpage.readLine()) != null) { if (aline.indexOf("datapunter") != -1) { DP = DP + 1; } } System.out.println("The name datapunter was found "+DP+" times."); // when all lines from the webpage are read close the BufferedReader object and // by closing that object we automatically close the stream to the URL Readpage.close(); } // end bracket of main() method } // end bracket of ReadPage program