我正在尝试实现JNotify。但是当我编译程序时,我收到了一些奇怪的错误消息。我从这个网站获得示例代码ttp://jnotify.sourceforge.net/sample.htmlJNotify中的错误异常访问冲突
作为信息,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
有没有人遇到过这种类型的错误?任何帮助将不胜感激。 谢谢
对于代码示例,使用代码按钮(10101010)或缩进至少4个空格的所有内容。我为你修好了。 – 2010-10-01 17:15:16
第一次使用这里。感谢您的纠正。 :-) – jacobian 2010-10-01 17:35:51