3 Replies Latest reply: Apr 23, 2007 2:22 PM by 807596 RSS

    help with registering for events from Windows

    807596
      Hi,

      Im developing a P2P backup system for LANs in Java. I have the following problem
      Lets say there is a file called test.txt in my Windows file system. My software is running on Windows at this time. The user opens up the file through Windows Explorer and modifies it or deletes it altogether.
      Is there a way I can ask WIndows to alert my software when this happens.? Essentially I need a way to give a list of files to Windows and then listen for any activity on those files

      Many thanks for your help and time
        • 1. Re: help with registering for events from Windows
          807596
          You can do this two ways.

          First, you make use of the Java Native Interface. Write a native library for Windows that uses the .NET class, FileSystemWatcher.

          This next one isn't the greatest approach. It's more a brute force way, but it still works. Write your own FileSystemListener class that gets a list of files, and checks the timestamp of it's last modification and compares the two.
          • 2. Re: help with registering for events from Windows
            807596
            Thanks for your reply.

            Can you please provide some more details about JNI. I am unable to find any quick tutorials on this topic on the Web. Most of them refer to the book. I have never heard of this before, so if you can provide a link that quickly explains file system interfaces, that would be very helpful.
            • 3. Re: help with registering for events from Windows
              807596
              JNI
              http://www.acm.org/crossroads/xrds4-2/jni.html

              FileSystemWatcher
              http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher(VS.71).aspx

              .NET and JNI
              http://www.devx.com/interop/Article/19845/1954?pf=true