逐語https://www.dazhuanlan.com/2019/08/25/5d625ec2c8207/
直接コードに
1 |
パスパス= Paths.get(「パス」)。もし(Files.exists(パス)){ 試みる(WatchService watchService = FileSystems.getDefault()newWatchService()){ path.register( watchService、 StandardWatchEventKinds.ENTRY_CREATE、 StandardWatchEventKinds.ENTRY_MODIFY、 StandardWatchEventKinds.ENTRY_DELETE )。一方、(真){ WatchKeyキー= watchService.take()。 //阻塞用(WatchEventイベント<?>:key.pollEvents()){ |
いくつかの注意事項
- あれば登録は、単一の文書の監視をサポートしていません
path
ではない文档夹
スローjava.nio.file.NotDirectoryException