After searching a little more (also bugs.java.com) I realized that my testcase 
can be improved, here a cleaner version, that still shows the same problem:

package fileevent;

import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;

import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;

public class Testcase {

  public static void main(String[] args) {
    try {
      Path dir = Paths.get(args[0]);
      FileSystem fs = dir.getFileSystem();
      WatchService watchService = fs.newWatchService();
      WatchKey watchKey = dir.register(watchService, ENTRY_MODIFY);
      for (;;) {
        for (WatchEvent<?> event : watchService.take().pollEvents()) {
          WatchEvent.Kind<?> kind = event.kind();
          if (kind == ENTRY_MODIFY) {
            @SuppressWarnings("unchecked")
            WatchEvent<Path> ev = (WatchEvent<Path>) event;
            Path file = ev.context();
            System.out.println("File-Changed: " + file);
          }
        }
        watchKey.reset();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

bugs.java.com showed no interesting entries for my problem (searched with 
keyword: WatchEvent)

If you think I should open a bug there I'll do so, however I have opened a bug 
quite some time ago and never heard anything back from the oracle guys ...

Best regards
Stefan


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to