import java.net.*;
import java.io.*;
import java.util.*;



public class A{

public static void main(String args[]){

 try {
	

	System.getProperties().put( "proxySet", "true" );
	System.getProperties().put( "proxyHost", "java" );
	System.getProperties().put( "proxyPort", "80" );
	String strUrl="http://profiles.yahoo.com/dheerendra_itbhu";
	URL url = new URL(strUrl);
    
        // Read all the text returned by the server
	while(true){
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {
            // str is one line of text; readLine() strips the newline character(s)
		if(str.indexOf("I'm online now!")!=-1){
		writeTimeToFile(str,strUrl);
	}
        }
        in.close();
	Thread.sleep(60000);
	}
    } catch (MalformedURLException e) {
	System.out.println("HereExcMal");
    } catch (IOException e) {
	System.out.println("HereExcIO");
	e.printStackTrace();

    } catch (Exception e) {
	System.out.println("HereExc");
	e.printStackTrace();

    }
}

public static void writeTimeToFile(String str,String strUrl){
try {
	Calendar cal=Calendar.getInstance();
        BufferedWriter out = new BufferedWriter(new FileWriter("c:/TestJava/Dheeru.doc",true));
        out.write("Reading "+strUrl+"  at this time "+cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+"\n");
        out.close();
    } catch (IOException e) {
    }
}

}
