JAVA-619: Split or move core-java-modules/core-java-io-apis module
This commit is contained in:
@@ -13,3 +13,4 @@ This module contains articles about Apache Commons libraries.
|
||||
- [Apache Commons BeanUtils](https://www.baeldung.com/apache-commons-beanutils)
|
||||
- [Histograms with Apache Commons Frequency](https://www.baeldung.com/apache-commons-frequency)
|
||||
- [An Introduction to Apache Commons Lang 3](https://www.baeldung.com/java-commons-lang-3)
|
||||
- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](https://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library)
|
||||
@@ -57,6 +57,11 @@
|
||||
<artifactId>xchart</artifactId>
|
||||
<version>${xchart-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${common-io.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
@@ -68,6 +73,7 @@
|
||||
<commons.dbutils.version>1.6</commons.dbutils.version>
|
||||
<xchart-version>3.5.2</xchart-version>
|
||||
<common-math3.version>3.6.1</common-math3.version>
|
||||
<common-io.version>2.5</common-io.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.dirmonitoring;
|
||||
|
||||
import org.apache.commons.io.monitor.FileAlterationListener;
|
||||
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DirectoryMonitoringExample {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DirectoryMonitoringExample.class);
|
||||
|
||||
private static final int POLL_INTERVAL = 500;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FileAlterationObserver observer = new FileAlterationObserver(System.getProperty("user.home"));
|
||||
FileAlterationMonitor monitor = new FileAlterationMonitor(POLL_INTERVAL);
|
||||
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
|
||||
@Override
|
||||
public void onFileCreate(File file) {
|
||||
LOG.debug("File: " + file.getName() + " created");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
LOG.debug("File: " + file.getName() + " deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileChange(File file) {
|
||||
LOG.debug("File: " + file.getName() + " changed");
|
||||
}
|
||||
};
|
||||
observer.addListener(listener);
|
||||
monitor.addObserver(observer);
|
||||
monitor.start();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user