Linux + Java + Windows: check if the file is fully copied

I have a Java application that monitors the directory for new files and processes any new file that it sees in the directory. The application should run on both linux and windows env. The problem is Linux, when the user manually copies the file to the directory, the application selects the file before it is fully copied to the directory. I tried to lock the file using various methods , but the application can get a lock in the file, even if the file is still copied by the linux system. I am also considering checking the file with the lsof command , but it is specific to Linux, so I try to avoid this.


Can anyone suggest a way to prevent the file from being downloaded by the application? Thanks in advance.

+4
source share
3 answers

You can check the file size for a certain interval, like 2 seconds, and if another file is copied, if not, you can go :)

0
source

One way to achieve this goal is that when your program detects that a new file exists in the directory, it can add this file to the list and periodically check the size of each item in the list as follows:

File # Length

, .

0

Perhaps the solution is the answer of this publication. You can try with jpoller .

0
source

Source: https://habr.com/ru/post/1663706/


All Articles