aspose file tools*
The moose likes Java in General and the fly likes file change notification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "file change notification" Watch "file change notification" New topic
Author

file change notification

christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
Hi,

I'm trying to implement a file change notification. I mean i want to be notifyed when some changes occured in a directory.
I can't use java 7 ...

I want to use DefaultFileMonitor from Apache common.


Here is a sample code which is working :


My problem comes from the Thread.sleep (20000), I would the program to run until explicitely called.

Any help would be appreciated.

Christohpe
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I would the program to run until explicitely called.

For example, how do you intend to stop it ?


[My Blog]
All roads lead to JavaRanch
christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
fm.stop()
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I mean the main program, when and how do you want to stop it ? You are watching a directory for changed, aren't you ? This is supposed to run until when ?
christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
I will run this in a struts web application with start and stop button.
Thanks
christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
or I will start it in a filter and stop it in the destroy method of the servlet
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

In a web application, this will be fine, as you can leave the file monitor running until the web application is shutdown, or until you explicitly call the stop() method. But in your example, which is not a web application, you need some sort of information to make it stop. For example, you could loop for ever and wait until you press a certain key.
christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
thanks you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file change notification