I have a non-Java program writing files to a directory. My Java program then copies these files to a different directory. Is there a way for Java to check if the last file is fully written to before being copied? This is because when I copy the files, the last file is still being written/processed to by the other program and the Java copy results in only a partial copy of it.
I have looked at doing something like this (Taken from answer here: https://stackoverflow.com/a/17603619/19297684):
boolean success = potentiallyIncompleteFile.renameTo(stagingAreaFile);
where the program attempts to rename the last file. However, this is not platform agnostic.
There is no reliable and OS independent way for Java to get this solved.
Other platforms that need to solve this problem (e.g. Apache Camel) use various strategies (some of them already mentioned in the comments to your question):
There is no general solution that fits all individual problems.