java jnotify_JNotify使用

package

org.test;

import net.contentobjects.jnotify.JNotify;

import net.contentobjects.jnotify.JNotifyAdapter;

import net.contentobjects.jnotify.JNotifyException;

public class EnhancedJNotifyAdapter extends JNotifyAdapter

{

private static final String REQUEST_BASE_PATH =

"D:/prot";

String path = REQUEST_BASE_PATH;

int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED

| JNotify.FILE_MODIFIED

| JNotify.FILE_RENAMED;

boolean watchSubtree = true;

public int watchID;

public static void main(String[] args) {

new EnhancedJNotifyAdapter().beginWatch();

}

public void beginWatch() {

try {

this.watchID = JNotify.addWatch(path, mask, watchSubtree,

this);

System.err.println("jnotify

-----------启动成功-----------");

} catch (JNotifyException e) {

e.printStackTrace();

}

// 死循环,线程一直执行,休眠一分钟后继续执行,主要是为了让主线程一直执行

//

休眠时间和监测文件发生的效率无关(就是说不是监视目录文件改变一分钟后才监测到,监测几乎是实时的,调用本地系统库)

while (true) {

try {

Thread.sleep(60000);

} catch (InterruptedException e) {// ignore it

}

}

}

public void fileCreated(int wd, String rootPath, String name)

{

System.err.println("fileCreated, the created file path is " +

rootPath + "/" + name);

}

public void fileRenamed(int wd, String rootPath, String

oldName,

String newName) {

System.err.println("fileRenamed, the old file path is " +

rootPath + "/" + oldName + ", and the new file path is " + rootPath

+ "/" + newName);

}

public void fileModified(int wd, String rootPath, String name)

{

System.err.println("fileModified, the modified file path is "

+ rootPath + "/" + name);

}

public void fileDeleted(int wd, String rootPath, String name)

{

System.err.println("fileDeleted , the deleted file path is " +

rootPath + name);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值