Specific file monitor using Apache Commons VFS API

大城市里の小女人 提交于 2019-12-11 01:18:05

问题


I want to perform some operation after a file named (XXXXXX.txt) created in the specific directory. I just don't want to monitor the whole directory. How can i achieve this using Apache Commons VFS API? I tried with the below code, but it did not work out. Any idea about how to achieve this?

FileObject listendir1 = fsManager.resolveFile("C:\\Users\\Myname\\AppData\\Local\\Temp\\XXXXXXX.txt");
fileMonitor.addFile(listendir1);
fileMonitor.start();

回答1:


Try something like this:

 FileSystemManager fsManager = VFS.getManager();
 FileObject listendir = fsManager.resolveFile("/home/username/monitored/");
 DefaultFileMonitor fm = new DefaultFileMonitor(new CustomFileListener());
 fm.setRecursive(true);
 fm.addFile(listendir);
 fm.start();



回答2:


  1. Implement a custom monitor and over ride the fileCreated() method

  2. Create a concurrent queue which keeps the monitors of interest and remove it after use



来源:https://stackoverflow.com/questions/14376713/specific-file-monitor-using-apache-commons-vfs-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!