Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.IOException;
- import java.nio.file.*;
- import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
- import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
- import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
- public class Main {
- public static final String DIRECTORY_TO_WATCH = "D:/Test";
- public static void main(String[] args) throws IOException, InterruptedException {
- // write your code here
- Path toWatch = Paths.get(DIRECTORY_TO_WATCH);
- CommunicationServer server = CommunicationServer.getInstance();
- if(toWatch == null) {
- throw new UnsupportedOperationException("Directory not found");
- }
- // make a new watch service that we can register interest in
- // directories and files with.
- WatchService myWatcher = toWatch.getFileSystem().newWatchService();
- // CommunicationServer server = new CommunicationServer();
- // start the file watcher thread below
- MyWatchQueueReader fileWatcher = new MyWatchQueueReader(myWatcher, server);
- Thread th = new Thread(fileWatcher, "FileWatcher");
- th.start();
- // register a file
- toWatch.register(myWatcher, ENTRY_CREATE, ENTRY_MODIFY);
- th.join();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement