조각난 자바의 일부 지점 (C)

축 어적으로 https://www.dazhuanlan.com/2019/08/25/5d625ec2c8207/


직접 코드에

1 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
경로 경로 = 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 ()) {











WatchEvent <경로> EV = (WatchEvent <경로>) 이벤트,
경로 파일 = ev.context (); // 얻을 이벤트 문서

경우 (StandardWatchEventKinds.ENTRY_CREATE.equals (event.kind ())) { //创建时 }



경우 (StandardWatchEventKinds.ENTRY_MODIFY.equals (event.kind ())) { //修改时 }



IF (StandardWatchEventKinds.ENTRY_DELETE.equals (event.kind ())) { // 삭제 } } key.reset (); 지우기 성공적인 치료, 또는 후속 이벤트가 트리거 될 수 없다 후 큐 키 // } } 캐치 (IOException가 | 예외 : InterruptedException E) { e.printStackTrace (); }








몇 가지주의 사항

  • 경우에 등록, 하나의 문서의 모니터링을 지원하지 않습니다 path하지 文档夹던져java.nio.file.NotDirectoryException

추천

출처www.cnblogs.com/petewell/p/11408897.html