I have a Java application which monitors a directory for new files and process any new file it sees in the directory. Application needs to run on both linux and windows env. The issue is on linux, when a user manually copies a file in the directory, the application picks the file before it gets completely copied over to the directory. I have tried to lock the file using various methods, but application is able to acquire lock on the file even if the file is still being copied by the linux system. I have also consider to check the file using the lsof command, but it is linux specific, so I am trying to avoid that.
Can someone please suggest a way to prevent the incomplete file from being picked up by the application? Thanks in advance.