Вопрос

I know that it's possible to detect changes to a file, such as using the Linux inotify service, or something like the Java 7 WatchService.

However, what I wish to do is to not only detect that a file has changed, but also where within the file the change occurred.

I don't think there is any existing OS service, or native language API for achieving this (maybe I'm wrong), so I'm wondering if anyone could offer any advice on doing this.

For example, let's start off small with say a 1MB file, that could be randomly altered at any given file offset. Can anyone offer any advice on attempting to monitor the file for change, as well as determining where within the file the change occurred.

Any input or advice would be greatly appreciated.

Thanks

Это было полезно?

Решение

Keep 2 copies of the file and monitor the main one with OS monitor and when that fires do a binary diff (is it a binary file?) with the backup - see here for binary diff method https://superuser.com/a/125408

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top