我正在尝试实现JNotify。但是当我编译这个程序时,我收到了一些奇怪的错误信息。我从这个站点获取示例代码:ttp://jnotify.sourceforge.net fy.sourceforge.net/sample.html
作为信息,JNotify用于目录监控,这就是我的源代码的样子。
这是类watching.java的内容
import net.contentobjects.jnotify.JNotifyListener;
import net.contentobjects.jnotify.JNotify;
public class watching{
public void watching(String s) throws Exception {
// path to watch
String path = System.getProperty(s);
// 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 {
public void fileRenamed(int wd, String rootPath, String oldName,
String newName) {
print("renamed " + rootPath + " : " + oldName + " -> " + newName);
}
public void fileModified(int wd, String rootPath, String name) {
print("modified " + rootPath + " : " + name);
}
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);
}
}
}然后,这是名为nowwatch.java的主类
public class nowwatch
{
public static void main(String[] args) throws Exception
{
System.out.println("Hello World!");
watching hello = new watching();
hello.watching("C:/Users/Raden/Documents/Downloads");
}
}但是为什么会出现这样的错误呢?我已经截取了错误的屏幕,以便您可以通过单击此link来查看它
你们当中有没有人遇到过这种类型的错误?不过,任何帮助都将不胜感激。谢谢
发布于 2010-10-02 01:19:50
JNotify肯定会使用JNI来与操作系统相关的通知API进行交互。看起来JNotify里有个bug。你有没有试过在SourceForge上的JNotify论坛上提问?
发布于 2012-02-15 21:33:40
我们也有同样的问题。因为我们无论如何都要使用JNA,所以我们只使用了这个框架中的FileMonitor示例。就像一种护身符。
发布于 2012-07-30 18:22:56
如果系统要求提供jNotify.dll文件,请确保已将该文件放到窗口或jre/bin或jdk/bin中。然后试一试,它就会开始工作。
https://stackoverflow.com/questions/3840844
复制相似问题