首页 > 代码库 > JNotify
JNotify
http://jnotify.sourceforge.net/
JNotify通过JNI调用本地的方法.,(windows:xxx.dll,linux:xxx.so)
下载JNotify.
添加对应的文件到 System.getProperty("java.library.path")下.
添加jar
来自官网的文档: package jnotify; import net.contentobjects.jnotify.JNotify; import net.contentobjects.jnotify.JNotifyListener; /** * * @author D04 */ public class Jnotify { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { //System.out.println("path-->" + System.getProperty("user.home")); System.out.println("java.library.path-->" + System.getProperty("java.library.path")); new Jnotify().sample(); } public void sample() throws Exception { // path to watch // String path = System.getProperty("user.home"); String path = "D:\\testJnotify"; // 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 Listener()); // 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); if (!res) { // invalid watch ID specified. } } class Listener implements JNotifyListener { @Override public void fileRenamed(int wd, String rootPath, String oldName, String newName) { print("renamed " + rootPath + " : " + oldName + " -> " + newName); } @Override public void fileModified(int wd, String rootPath, String name) { print("modified " + rootPath + " : " + name); } @Override public void fileDeleted(int wd, String rootPath, String name) { print("deleted " + rootPath + " : " + name); } public void fileCreated(int wd, String rootPath, String name) { print("created " + rootPath + " : " + name); } void print(String msg) { System.err.println(msg); } } }
JNotify
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。