Paths类:创建路径Path
(1)创建本地路径:
static Path |
get(String first, String... more) |
(2)创建网络URL路径:
static Path |
get(URI uri) |
Path类:
(1)为某一个Path注册事件管理器WatchService,然后获得事件集合WatchKey,之后就可以获取具体事件的信息了。
WatchKey |
register(WatchService watcher, WatchEvent.Kind<?>... events) Registers the file located by this path with a watch service. |
例子:
WatchService watchService = FileSystems.getDefault().newWatchService();
Paths.get("").register(watchService,StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.OVERFLOW);
while (true){
WatchKey key = watchService.take();
for (WatchEvent event : key.pollEvents()){
WatchEvent.Kind kind= event.kind();
event.context();
}
}
(2)比较path路径的信息
boolean |
boolean |
startsWith(Path other) |