commons-vfs是一个强大的虚拟文件系统,为操作各种各样的文件系统提供了统一API。这里使用的是commons-vfs2。
直接代码
package dusk;
import org.apache.commons.vfs2.*;
import org.apache.commons.vfs2.impl.DefaultFileMonitor;
import org.junit.Test;
import java.io.File;
/**
* Created by dushangkui on 2017/4/24.
*/
public class ListenerTest {
@Test
public void test(){
try {
FileSystemManager fsm = VFS.getManager();
FileObject file = fsm.resolveFile(new File("D://vfs").getAbsolutePath());
DefaultFileMonitor fileMonitor = new DefaultFileMonitor(new FileListener() {
@Override
public void fileCreated(FileChangeEvent event) throws Exception {
resolveEvent("Created",event);
}
@Override
public void fileDeleted(FileChangeEvent event) throws E