1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
AgentTailerListener listener = new AgentTailerListener();
Tailer tailer;
WatchService watcher = FileSystems.getDefault().newWatchService();
while (true) {
WatchKey watchKey;
watchKey = Paths.get("/tmp").register(watcher, ENTRY_CREATE);
watchKey = watcher.take();
for (WatchEvent<?> event : watchKey.pollEvents()) {
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
tailSource = event.context().toString();
System.out.println(tailSource);
File file = new File(tailSource);
tailer = TailerFactory.createTailer(file, listener);
(new Thread(tailer)).start();
}
}
watchKey.reset();
} |
Partager