1 голос
 
454 просмотра
11.07.2019 / 08:58  Aladdin

WatchService не отображает все события

  1. private void runWatchService() throws IOException {
  2.     File path = new File("F:/TempFolder/");
  3.  
  4.     WatchService watchService = FileSystems.getDefault().newWatchService();
  5.     Path dirPath = path.toPath();
  6.     dirPath.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
  7.  
  8.     for(;;) {
  9.         WatchKey key;
  10.         System.out.println("wait");
  11.         try {
  12.             key = watchService.take();
  13.             StringBuilder builder = new StringBuilder("Upload Files:");
  14.             for (int i = 0; i < key.pollEvents().size(); i++) {
  15.                 WatchEvent event = key.pollEvents().get(i);
  16.                 Path eventPath = ((WatchEvent<Path>) event).context();
  17.                 builder.append("\n").append(eventPath.getFileName().toString());
  18.             }
  19.         System.out.println(builder.toString());
  20.         } catch (InterruptedException ex) {
  21.             throw new RuntimeException(ex);
  22.         }
  23.  
  24.     }
  25. }

этот метод выводит ошибку в строке 15.
14 строке получаю poolEvents с размером 1 а в 15 строке 0.
в чем может быть проблема?
Изм. Aladdin от 11.07.2019 / 08:58
11.07.2019 / 12:36  aNNiMON
этот метод выводит ошибку в строке 15. Какую? :кек2:
14.07.2019 / 06:14  Aladdin
Opps!14 строке проверяем не пуст ли список, не пуст (даже дебаг делал)
15 строке уже список становится пустым
получаю ArrayIndexOutOfBoundsException
Ответы
Ответов нет
Всего: 0

Реклама

Мы в соцсетях

tw tg yt gt