0

I am trying to write an Application which lists down the files from the server . Now I want to give users to open any file from the list (Windows) with any editor for example a text file and User opens with NotePad++.

Now is there anyway I can know that if user saves the file,if yes, then I would upload the file back to the server.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Makky
  • 17,117
  • 17
  • 63
  • 86

2 Answers2

1

Use File#lastModified() to get the time at which the file was lastly modified.

1

There is a tutorial about Watching a Directory for Changes describing the WatchService which was introduced in Java 7. You can use this service to monitor files and directories:

WatchService watcher = FileSystems.getDefault().newWatchService();
Path dir = ...;
try {
    WatchKey key = dir.register(watcher,
                           StandardWatchEventKinds.ENTRY_CREATE,
                           StandardWatchEventKinds.ENTRY_DELETE,
                           StandardWatchEventKinds.ENTRY_MODIFY);
} catch (IOException x) {
    System.err.println(x);
}
Kai
  • 38,985
  • 14
  • 88
  • 103
  • Thanks a lot but I am limited to use Java 1.6. – Makky May 22 '13 at 12:48
  • Its quuite an unfortunate that Ican't use that service. Do you have any alternative on your mind ? – Makky May 22 '13 at 12:51
  • @Makky Then check out this question: [WatchService for Java 6](http://stackoverflow.com/questions/7968488/watchservice-for-java-6) – Kai May 22 '13 at 12:51