J'essaye d'implémenter JNotify. mais je reçois des messages d'erreur un peu étranges lorsque j'ai compilé le programme. Je reçois l'exemple de code de ce site ttp: //jnotify.sourceforge.net/sample.htmlerreur exception violation d'accès dans JNotify
En tant qu'information, JNotify est utilisé pour la surveillance de répertoire et c'est ainsi que mon code source ressemble.
c'est le contenu de la classe 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);
}
}
}
alors c'est la classe principale qui a nommé 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");
}
}
mais pourquoi l'erreur est allé comme ça? J'avais une capture d'écran l'erreur de sorte que vous pouvez le voir en cliquant sur ce link
l'un de vous a-t-il déjà connu ce type d'erreur? toute aide serait appréciée cependant. merci
Pour les exemples de code, utilisez le bouton de code (10101010) ou indentez tout au moins 4 espaces. Je l'ai réparé pour vous. –
premier utilisateur ici.merci de la correction. :-) – jacobian