title: Check when all file handles are released in Java
body: <p>I want to monitor a directory, and when a file appears there open it, process it and then move it to another directory. The problem is how to check that the other program is done writing it. With Java 7, I can use a WatchService from FileSystem, but I can only check when the files are created. What I want is to know when all file handles are released.</p>
  
  <p>My first thought was that I could obtain an exclusive lock, but it turned out that it was possible to kick out another application while it was actually updating the file.</p>
  
  <p>What is the preferred way to do this in Java? Thanks!</p>