ciao!
sto implementando un programmino che mi permetta di vedere eventuali modifiche / creazioni / cancellazioni di file sul file server condiviso in rete.
per ora ho fatto così:
e il main:codice:public class Watcher implements Runnable { private final WatchService watchService; public Watcher(WatchService ws) { this.watchService = ws; } @Override public void run() { try { WatchKey key = watchService.take(); while (key != null) { for (WatchEvent event : key.pollEvents()) { System.out.printf("Received %s event for file: %s\n", event.kind(), event.context()); } key.reset(); key = watchService.take(); } } catch (InterruptedException ex) { System.out.println(ex.getMessage()); } System.out.println("Stopping thread"); } }
tutto ciò funziona, però vorrei aggiungere la possibilità di vedere da chi è stata fatta l'operazione.codice:public static void main(String[] args) throws IOException, InterruptedException { Path folder = Paths.get("......."); if (folder == null) { throw new UnsupportedOperationException("Directory not found"); } WatchService ws = folder.getFileSystem().newWatchService(); Watcher w = new Watcher(ws); Thread th = new Thread(w, "Watcher"); th.start(); folder.register(ws, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); th.join(); }
se proprio non può essere il nome del pc, anche l'ip mi andrebbe bene.
cmq risalirei facilmente al pc visto che gli ip sono tutti statici.
avete idea se possibile??

Rispondi quotando
