Thomas Darimont
Erfahrenes Mitglied
Hallo,
schaut mal hier:
Wenn ich nun in der shell in /tmp/ ein
echo xxx>test1.data
absetze bekomme ich die Ausgabe:
Mehr dazu gibts hier:
http://openjdk.java.net/projects/nio/javadoc/java/nio/file/WatchService.html
http://openjdk.java.net/projects/nio/presentations/TS-5686.pdf
Ich weis aber noch nicht wie man den absoluten Pfad der geänderten Datei herausbekommt...
Gruß Tom
schaut mal hier:
Java:
package de.tutorials.training;
import static java.nio.file.StandardWatchEventKind.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKind.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKind.ENTRY_MODIFY;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.nio.file.WatchEvent.Kind;
public class FileSystemWatcherExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
WatchService watchService = FileSystems.getDefault().newWatchService();
System.out.println(watchService);
WatchKey watchKey = Paths.get("/tmp").register(watchService,new Kind<?>[] { ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE });
while (true) {
watchKey = watchService.take();
for (WatchEvent<?> watchEvent : watchKey.pollEvents()) {
System.out.println(watchEvent.kind() + " "
+ ((Path) watchEvent.context()));
}
watchKey.reset();
}
}
}
Wenn ich nun in der shell in /tmp/ ein
echo xxx>test1.data
absetze bekomme ich die Ausgabe:
Code:
ENTRY_CREATE test1.data
ENTRY_MODIFY test1.data
Mehr dazu gibts hier:
http://openjdk.java.net/projects/nio/javadoc/java/nio/file/WatchService.html
http://openjdk.java.net/projects/nio/presentations/TS-5686.pdf
Ich weis aber noch nicht wie man den absoluten Pfad der geänderten Datei herausbekommt...
Gruß Tom