Detecting file completion using WatchService in java

I have a file which is being constantly written to, while it is registered with watchService. Is it possible to detect that it has completed, using WatchEvent.

Please note that, by complete, I mean the previous writer which was writing to the file has finished and I expect no-one else to open that file and write.


I have faced the same problem on Windows paltform. I have tried to solve it using timeout: when a timeout of 1 second for example is elapsed (since the last modify event), I consider that file is complete. But it is not working for big files: I have remark that a modify event is fired after the timeout. In my application, I copy files on a directory. I solved the problem by copying a temporary file after the copy of my file. In this case, when a create event is fired for the temporary file, the first file is complete.

N.B: for linux platform, I've done some searching and I find a suggestion to use renameTo() method to check if the file still locked by a process. If the remaneTo() returns true, your file is complete. In my project, which is Windows dependant, I tried renameTo() but I get a true value and the file is not complete.

Need Your Help

How to mask bytes in ARM assembly?

assembly arm

i have got an 32bit (hexadecimal)word 0xaabbccdd and have to swap the 2. and the 3. byte. in the end it should look like 0xaaccbbdd

Managing libraries and imports in a programming language

c++ design-patterns interpreter

I've created an interpreter for a stupid programming language in C++ and the whole core structure is finished (Tokenizer, Parser, Interpreter including Symbol tables, core functions, etc.).