• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting notification when file has changed

 
Sam Su
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it still so that there are no listeners in Java to inform application that
certain file has changed? Are there any 'pattern' or best practice to get this
kind of functionality? Any sample code available?

Thanks all!

[ May 17, 2004: Message edited by: Sam Su ]
[ May 17, 2004: Message edited by: Sam Su ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your choices are to a) periodically list the directory and see if you see any new files or b) use JNI to talk to a C/C++ module that hooks up to the OS API. You'd have to provide a custom module per operating system, but if you're locked into only one that might not be a problem.

I notice Eclipse is aware of file changes outside the IDE, and would guess it's using the latter: JNI hook to listen to OS events.
 
Sam Su
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okey, so there should be e.g. a thread which whould read all information considering files in the directory after a certain time and then update new file information to a somekind of collection etc.

Jep, trying that kind of approach.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the all-Java way if you can live with the time latency between file changes and the next sweep. Throw the file array into a sorted list - it's pretty simple to compare two sorted lists.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!