In my application I watch a directory for new files.
I keep an array of current files obtained with Files.list(dir)
, process this list one file after another, and then reload the directory with Files.list()
again.
While I have never encountered the problem myself, a coworker told me that the predecessor software had an additional check that the file is older than 3 seconds (calculated with (Files.getLastModifiedTime(path) - System.currentTimeMillis()) > 3000
) because there were issues that incomplete transferred (or better: not yet fully transferred) files went into processing.
Can I make any assumptions that the files returned by Files.list()
were copied fully into the directory I am watching?
Is there a cleaner way to check if a file is complete? The 3 seconds check is more like a hack, a file with multiple GB in size could be copied over a slow connection (network) and may not be fully transfered even after 3s have passed.