1

I am need to create an event such that whenever a file is appended or edited, an event should be launched which would tell all its listeners at which file and line the data was edited, deleted, appended with what data.

Possible solution that I thought of is to cascade piped I/0 streams with threads and action listener, but I am unable to achieve the required solution with required speed, memory management, synchronizing which is to be compact.

Example: I am editing a 'txt' file in Windows Notepad; and as soon as I save it, the program running in the background launches an event which tells all its listeners the data was edited and does some processing on the data changed.

If there is already an implemented solution then please give a reference to it.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045

1 Answers1

1

I have not tried this, but looking at the documentation the FileSystem#newWatchService might be what you need. The usage (and examples) of that WatchService are available in the 'Oracle WatchService tutorial'.

Robin
  • 36,233
  • 5
  • 47
  • 99
  • See also [*WatchService for Java 6*](http://stackoverflow.com/questions/7968488/watchservice-for-java-6). – trashgod Jun 14 '12 at 20:29