首页 技术 正文
技术 2022年11月9日
0 收藏 498 点赞 4,184 浏览 1678 个字

一、理由

使用JNotify监测的更全面,更快速。

二、参考代码

import net.contentobjects.jnotify.JNotify;
import net.contentobjects.jnotify.JNotifyException;
import net.contentobjects.jnotify.JNotifyListener;public class Main implements JNotifyListener {
public static void main(String[] args) throws JNotifyException, InterruptedException {
// path to watch
String path = "/weatherdata";
System.out.println(System.getProperty("java.library.path")); // watch mask, specify events you care about,
// or JNotify.FILE_ANY for all events.
int mask = JNotify.FILE_CREATED
| JNotify.FILE_DELETED
| JNotify.FILE_MODIFIED
| JNotify.FILE_RENAMED; // watch subtree?
boolean watchSubtree = true; // add actual watch
int watchID = JNotify.addWatch(path, mask, watchSubtree, new Main()); // sleep a little, the application will exit if you
// don't (watching is asynchronous), depending on your
// application, this may not be required
Thread.sleep(1000000); // to remove watch the watch
boolean res = JNotify.removeWatch(watchID);
} int count = 0; @Override
public void fileCreated(int i, String s, String s1) {
System.out.println("fileCreated s=" + i + " i=" + s + " s1=" + s1);
} @Override
public void fileDeleted(int i, String s, String s1) {
System.out.println("fileDeleted s=" + s + " i=" + i + " s1=" + s1);
} @Override
public void fileModified(int i, String s, String s1) {
System.out.println("fileModified s=" + s + " i=" + i + " s1=" + s1);
} @Override
public void fileRenamed(int i, String s, String s1, String s2) {
System.out.println("fileRenamed s=" + s + " i=" + i + " s1=" + s1 + " s2=" + s2 + " count:" + (++count)); }
}

三、说明

如果启动时报找不到JNotify库(https://sourceforge.net/projects/jnotify/files/jnotify/jnotify-0.94/ 下载),请复制JNotify的最新版本库到系统相应库目录下。

System.getProperty("java.library.path")

在Windows上,复制jnotify_64bit.dll到:c:/windows下即可。

在Linux上,可以复制libjnotify.so到/usr/lib64目录下。

附件:https://files.cnblogs.com/files/songxingzhu/jnotify-lib-0.94.zip


    					
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295