Package java.nio.file

Examples of java.nio.file.WatchService


  @Override
  public void run() {
    try {
      Path evdev = Paths.get("/dev/input");
     
      WatchService watcher = evdev.getFileSystem().newWatchService();
      evdev.register(watcher, StandardWatchEventKinds.ENTRY_CREATE);
     
      WatchKey watckKey = watcher.take();
      List<WatchEvent<?>> events = watckKey.pollEvents();
      for (WatchEvent event:events) {
        if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
          String name = event.context().toString();
          if (filter.accept(input, name)) {
View Full Code Here


      process(StandardWatchEventKinds.ENTRY_CREATE, child);
    }

    FileSystem fileSystem = directory.getFileSystem();

    WatchService watcher = fileSystem.newWatchService();

    try {
      WatchKey key = directory.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
      if(key.isValid()){
        process(key);
      }

      while(key.reset()){

        try {
          key = watcher.take();
        } catch(InterruptedException ie){
          break;
        }

        if(key.isValid()){
          process(key);
        }
      }
    } finally {
      watcher.close();
    }
  }
View Full Code Here

TOP

Related Classes of java.nio.file.WatchService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.