package test.vfs;

import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.vfs2.FileChangeEvent;
import org.apache.commons.vfs2.FileListener;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.impl.DefaultFileMonitor; /**
* Hello world!
*
*/
public class App {
public static final Log log = LogFactory.getLog(App.class); public static void main(String[] args) {
FileSystemManager fsManager = null;
FileObject listendir = null;
try {
fsManager = VFS.getManager();
listendir = fsManager.resolveFile(new File("E://vfs").getAbsolutePath());
} catch (FileSystemException e) {
log.error("监视文件夹出错了", e);
e.printStackTrace();
} System.out.println(listendir.getName()); // 定义一个监视器及事件处理程序
DefaultFileMonitor fm = new DefaultFileMonitor(new FileListener() {
public void fileCreated(FileChangeEvent event) throws Exception {
monitor(event);
} public void fileDeleted(FileChangeEvent event) throws Exception {
monitor(event);
} public void fileChanged(FileChangeEvent event) throws Exception {
monitor(event);
} private void monitor(FileChangeEvent event) {
FileObject fileObject = event.getFile();
FileName fileName = fileObject.getName();
System.out.println(fileName.toString());
}
}); fm.setRecursive(true); // 设置为级联监控
fm.addFile(listendir); // 增加监控文件
fm.start(); // 启动监视器 for(;;){
try {
Thread.currentThread().sleep(1000);
System.out.println(System.currentTimeMillis());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

apache commons vfs 文件夹监控的更多相关文章

  1. Apache配置虚拟文件夹

    作为一个Android开发人员,一直以为,至少应该有一个server语言,最近慢慢学习php,当然学习Apache使用.本文介绍Win7环境下,怎样配置Apache的虚拟文件夹. 首先,找到我们Apa ...

  2. Java高级应用(一个)-文件夹监控服务

    最近.在研究一些比较成熟的框架.他们还发现,他们中的一些相当不错的文章.现在,对于一些在你们中间一个简单的翻译(版的英文文章,非常有帮助). 译:原文链接 你有没有发现,当你编辑一个文件.同一时候使用 ...

  3. php apache用户写文件夹权限设置

    php一般是以apache用户身份去执行的,把apache加入到存储你文件的父文件夹属组里去,然后改该父文件夹权限为775,这样属组成员就有写的权限,而apache属于这个组就可以改写该目录下所有文件 ...

  4. org.apache.commons.vfs 配置文件里面 密码包含 @

    登录ftp的用户名 sftpuser ,密码 @sftpuser 在配置文件里面 需要 把 @ 转义 成 %40 ftppath=sftp://sftpuser:%40sftpuser@127.0.0 ...

  5. apache设置映射文件夹的配置方法

    在apache的配置文件中加入以下配置 Alias /uploadImage F:/upload <Directory F:/upload/UploadFiles>      Option ...

  6. DotNetCore跨平台~Quartz热部署的福音~监控文件夹的变化

    在DotNetCore出来之后,同时也使用了quartz进行调度中心的设计,将它做到docker里方便部署,在之前的quartz版本里支持配置文件的方式,而现在不支持了,我们应该去想一下,为什么不去支 ...

  7. Maven+Spring Batch+Apache Commons VF学习

    Apache Commons VFS资料:例子:http://www.zihou.me/html/2011/04/12/3377.html详细例子:http://p7engqingyang.iteye ...

  8. CentOS7.0 x86_64系统上构建php开发环境--Lamp(包含设置虚拟文件夹,加入SELinux对httpd的支持等知识)

    一.安装mysql,直接用yum安装就可以,mysql在centos7.0版本号中被mariadb替代了. 命令: yum install mysql-server mysql 安装好了,选择改动my ...

  9. 文件及文件夹更改通知/监测软件TheFolderSpy

    TheFolderSpy是Windows环境下一个监测文件(夹)更改,删除,创建,重命名的绿色免安装小软件,并在文件及文件夹有更改时发送Email通知管理者 该软件使用.Net开发,所以需要安装.Ne ...

随机推荐

  1. Xcode7推出的新优惠:免证书测试

    1.准备 注意:一定要让你的真机设备的系统版本和app的系统版本想对应,如果不对应就会出现一个很常见的问题:could not find developer disk image 2.首先先安装Xco ...

  2. UILocalNotification详解

    以下内容来自网络 本地Notification所使用的对象是UILocalNotification,UILocalNotification的属性涵盖了所有处理Notification需要的内容.UIL ...

  3. Zipper_DP

    Description Given three strings, you are to determine whether the third string can be formed by comb ...

  4. FTP服务器移动文件目录

    已经可以移动文件了,原因是路径问题.还是用的Rename方法.原因是RenameTo=“”;这里的路径之前没包含文件名,而且相对路径和绝对路径都没弄对,所以之前一直不相信别人说的Rename可以移动文 ...

  5. Word Ladder II

    Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformat ...

  6. 11. Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  7. 264. Ugly Number II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  8. cve-2015-1635 poc

    import socket import random ipAddr = "10.1.89.20" hexAllFfff = " req1 = "GET / H ...

  9. How can I create an executable JAR with dependencies using Maven?

    http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using ...

  10. css float对于之后布局的影响

    后面的元素不浮动,即便设置了宽度,表面上只占了一定的宽度,但实际上占了全屏.(所以设置了overflow之后,并且之后的div设置了宽度,再设置margin-left可能不起作用). 高度对浮动的影响 ...