> 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
[quoted text clipped - 16 lines]
> How can I know when the copy process is complete. (Also, this has to
> work on both Windows and FreeBSD).

Signature
Knute Johnson
email s/nospam/knute/
>> 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
[quoted text clipped - 19 lines]
> It stops throwing the exception. What's the problem here? If it throws
> this exception just wait for a few seconds and try again.
Because it's almost always a bad idea to have exceptions thrown in the
normal course of execution. Exceptions are just that -- unusual cases.
Besides, there's no guarantee that this method will work in a
cross-platform way. Maybe a particular operation system doesn't throw
the exception. Then my app would start processing a partially-copied
file, leading to all kinds of problems.
opalpa opalpa@gmail.com http://opalpa.info - 06 Mar 2007 03:40 GMT
I believe BSD, being a unix, would not throw the exception.
As for throwing exceptions, I've personally changed my mind on
throwing exceptions in course of execution. I used to treat exception
as a synonym for error. Currently I occasionally treat exceptions as
a control flow mechanism.
opalpa
opalpa@gmail.com
http://opalpa.info/
opalpa opalpa@gmail.com http://opalpa.info - 06 Mar 2007 05:16 GMT
> I believe BSD, being a unix, would not throw the exception.
The possible absence of this exception is another reason to keep the
operation of coping the files and the operation of processing the
files seperate in sequence. If the format of the file permits a
subsequence to be a valid file then reading a file too early could
chop of information.
---
I'm suprised to learn FileNotFoundException covers inaccseibility to
file. I would have guessed that IOException gets thrown.
opalpa
opalpa@gmail.com
http://opalpa.info/
Knute Johnson - 06 Mar 2007 04:18 GMT
>>> 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
[quoted text clipped - 22 lines]
> Because it's almost always a bad idea to have exceptions thrown in the
> normal course of execution. Exceptions are just that -- unusual cases.
I think an incomplete file would be an unusual situation, it's certainly
not what you want to find.
> Besides, there's no guarantee that this method will work in a
> cross-platform way. Maybe a particular operation system doesn't throw
> the exception. Then my app would start processing a partially-copied
> file, leading to all kinds of problems.
I think you're toast. The only other idea I have is to check
periodically to see if the file size stops changing. But I'm not sure
that is good either because I have seen file systems that set the length
of the file before completing the write. You might try reading it again
and again until it's checksum becomes stable.
You might just try using both the exception and the lock. See if that
works on most OS.

Signature
Knute Johnson
email s/nospam/knute/