我正在嘗試實現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