I was wondering if there is some sort of Java code that can get information from a webite ONLY when it needs to.

To better explain (by using an example) let's say I have a slow webpage (minimal traffic) where a user clicks a button and Java opens my DVD drive (Cause why not :P ). The easy way would be to read a file from the website every x seconds, but I don't want that because that would drive bandwidth and all that up (in this example remember, it's a slow webpage).

I want to know if I can get Java to NOT loop through a file every so often, but still open that DVD drive when a user clicks that button.

I would prefer if the webpage side was in PHP, if that is possible.

If the above is not possible, is it possible for Java to read when a file was last updated? If so, how? (I don't want to use a looping method, but with the "last updated" info I can choose whether to read the file or not, reducing some usage)

Please and thank you :)


I don't know if your first "solution" will be possible or not... But I do know that there is a method of the File class called "lastModified()".

The lastModiied method returns a long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs


long lastUpdated = myFile.lastModified();

Hope this helps!

This question has already been answered. Start a new discussion instead.