I am using WatchService of NIO. Two classes to watch a specific directory (Ubuntu 11.10).
Whenever a change is made, for example if I modify a existing file, it fires a MODIFIED event 2 times. Don’t know why? It works fine when I create new file.
I found a solution for it. It fires two modify events, because when the filesystem writes new files, it creates it with zero byte and fires create event and then it writes data to the and file then it fires the modify event.
The same applies with modifications. When we modify an already existing file, the filesystem first creates it with 0 bytes and fires a modify event and then writes data to it. Then it fires the modify event again. That’s why I was receiving two modify events.