0

I would like to ask if there any Java API which can fire events, when a specific line on the txt file change and which line is change, modified or delete? If not, I would like to point me the direction to look about it!

Thanks

KostasC
  • 1,076
  • 6
  • 20
  • 40

2 Answers2

1

There is no such API in the Java standard library. The WatchService API allows you to detect when your .txt file is changed, but detecting which line is changed is something that you'll need to implement yourself.

In order to do that, you need to store the contents of the file as a list of lines, and when you receive a change notification, read the file again and compare the new contents with the contents you've previously stored.

yole
  • 92,896
  • 20
  • 260
  • 197
0

If you're targeting Linux, you can use the inotify system API. I know two Java projects to do that : - JNotify : http://jnotify.sourceforge.net/ - inotify-java : https://www.openhub.net/p/inotify-java

I hope this helped ;)

mrgeek
  • 117
  • 1
  • 4