Read URL in Java track changes

I want to develop a desktop application using Java which will alert me whenever there is any change in a specific URL(say a blog). Can you guide me how can I go about it? Or can you suggest me things(say java.io.*, java threads, events etc) I should use to develop such an application?

Thanks in advance.

[317 byte] By [anurag_patila] at [2007-11-27 7:51:04]
# 1

First, there's the planning

1. How often do you want to check? If you make a request every second, the site may quickly think you are doing a DOS attack. Maybe time it for once every 10 minutes or so? Or maybe it changes less than that and you could do once a day.

2. See the java.net.URLConnection. Within that you can get the last modified date. This is what you should use. If the last mod date hasn't changed, then don't load the page.

BTW the fact that creating a URL object requires you to catch a MalformedURLException is such a stupid, bad implementation.

... There, I've had my two cents

tjacobs01a at 2007-7-12 19:32:10 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you tjacobs01. However, what do you mean by "BTW the fact that creating a URL object requires you to catch a MalformedURLException is such a stupid, bad implementation."?Thank you again.
anurag_patila at 2007-7-12 19:32:10 > top of Java-index,Java Essentials,Java Programming...
# 3

> Thank you tjacobs01. However, what do you mean by

> "BTW the fact that creating a URL object requires you

> to catch a MalformedURLException is such a stupid,

> bad implementation."?

Just one of my gripes with java. I hate having to always put a try catch block around this even though I've never encountered an MUE. Maybe it's not that bad, maybe its just that the File.toURL throws MUE is really stupid and really gets under my skin.

tjacobs01a at 2007-7-12 19:32:10 > top of Java-index,Java Essentials,Java Programming...
# 4

Thank you tjacobs01 for your reply. I have written a program which returns me number of milliseconds since URL was last modified. However, I want to track changes every second, how can I do that?

This is my program:

import java.net.*;

import java.io.*;

public class test

{

public static void main(String args[])

{

try

{

URL url = new URL("http://www.yahoo.com");

URLConnection urlc = null;

urlc = url.openConnection();

long l = urlc.getLastModified();

System.out.println(l);

}

catch(MalformedURLException mue)

{

System.out.println(mue);

}

catch(IOException ioe)

{

System.out.println(ioe);

}

}

}

Thank you.

anurag_patila at 2007-7-12 19:32:10 > top of Java-index,Java Essentials,Java Programming...
# 5
Use java.util.Timer and schedule it according to your time.
jackwenttohilla at 2007-7-12 19:32:10 > top of Java-index,Java Essentials,Java Programming...