Advertisement
murkata86

Main

Mar 16th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.*;
  5.  
  6. import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
  7. import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
  8. import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
  9.  
  10. public class Main {
  11.  
  12.     public static final String DIRECTORY_TO_WATCH = "D:/Test";
  13.  
  14.     public static void main(String[] args) throws IOException, InterruptedException {
  15.         // write your code here
  16.         Path toWatch = Paths.get(DIRECTORY_TO_WATCH);
  17.         CommunicationServer server = CommunicationServer.getInstance();
  18.         if(toWatch == null) {
  19.             throw new UnsupportedOperationException("Directory not found");
  20.         }
  21.  
  22.         // make a new watch service that we can register interest in
  23.         // directories and files with.
  24.         WatchService myWatcher = toWatch.getFileSystem().newWatchService();
  25.         // CommunicationServer server = new CommunicationServer();
  26.  
  27.         // start the file watcher thread below
  28.         MyWatchQueueReader fileWatcher = new MyWatchQueueReader(myWatcher, server);
  29.         Thread th = new Thread(fileWatcher, "FileWatcher");
  30.         th.start();
  31.  
  32.         // register a file
  33.         toWatch.register(myWatcher, ENTRY_CREATE, ENTRY_MODIFY);
  34.         th.join();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement