Currently I’m working on the project that does processing files from source directory in one of it’s routines. There’s a Java process that’s looking for specified directory and tries to read and process files if they exist. Files are quit large and updates by other thirdparty process. The question is how can I check if the file is completely written? I’m trying to use file.length() but looks like even if writing process hasn’t been completed it returns actual size. I have a feeling that solution should be platform dependent. Any help would be appreciated.
UPDATE:
This question is not really different from the duplicate but it has an answer with working code snippet that is highly rated.
Does the producer process close the file when its finished writing? If so, trying to open the file in the consumer process with an exclusive lock will fail if the producer process is still producing.