C
Chris
My app processes files as they get dropped into a directory. There's a
loop that keeps checking if a file is available, and if it is, then the
file gets read.
The trouble is that if the app detects a new file before it has been
fully copied from another location, and it starts processing, then I get
errors. Somehow, I need to be able to detect when the copy process has
completed.
I tried to test for an exclusive file lock using NIO, but it did not
work. In order to lock a file, you have to open it first, and I get a
FileNotFoundException when I create a FileInputStream on the file.
java.io.FileNotFoundException: C:\mydir\product.xml (The process cannot
access the file because it is being used by another process)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
How can I know when the copy process is complete. (Also, this has to
work on both Windows and FreeBSD).
loop that keeps checking if a file is available, and if it is, then the
file gets read.
The trouble is that if the app detects a new file before it has been
fully copied from another location, and it starts processing, then I get
errors. Somehow, I need to be able to detect when the copy process has
completed.
I tried to test for an exclusive file lock using NIO, but it did not
work. In order to lock a file, you have to open it first, and I get a
FileNotFoundException when I create a FileInputStream on the file.
java.io.FileNotFoundException: C:\mydir\product.xml (The process cannot
access the file because it is being used by another process)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
How can I know when the copy process is complete. (Also, this has to
work on both Windows and FreeBSD).