java
WatchService와 Apache Commons IO Monitor (파일시스템 변경 감지)
파일시스템 변경을 감지해야 할 경우가 있다. 특정 디렉토리에 파일 변경(추가/삭제/수정)이 발생한 경우를 주기적으로 모니터링 해야 하는 경우이다. 기본적으로 아래의 두 가지 방법이 있다. WatchService 사용 Apache Commons IO Monitor 라이브러리 사용 1. WatchService 동작 방식 WatchService를 사용하는 첫 번째 단계는 java.nio.file.FileSystem 인스턴스를 생성하는 것이다. WatchService watchService = FileSystems.getDefault().newWatchService(); 그 다음 모니터링 할 디렉토리 경로를 만들자. Path path = Paths.get("pathToDir"); 이 단계 이후에 Standard..
2023. 11. 1. 20:06