Hi all,
i have an application that periodically checks a directory for the
existence of some files, then move them somewhere. Those files are
copied there locally, or uploaded from a remote client.
My question is, how can i know if a file is still in the midst of
"being placed there"?
Say, a file is uploaded to that directory from a remote client, and
the upload takes some time. If i use File.exists(), it would return
true as soon as the upload has started. However, i do not want to move
that file before the upload has totally completed. How can i do this?
Thanks in Advance,
Edwin
rayzyang@gmail.com - 14 Mar 2007 10:14 GMT
> Hi all,
>
[quoted text clipped - 12 lines]
> Thanks in Advance,
> Edwin
Hi,I have some ideas on your question.Whether the file's transmission
is completed is depend on your IO stream used for reading then writing
the file through disc.So,you can just flush the Writer or OutputStream
and continue you work,if there is no IOException cast.
Furthermore,there is several upload components which can dispose the
file uploading quite well ,such as,SmartUpload,apache's common upload
package.You can try if you wish.
rayzyang
Gordon Beaton - 14 Mar 2007 10:26 GMT
> My question is, how can i know if a file is still in the midst of
> "being placed there"?
In general there is no way to know that a file might still be written
to by another process.
Your application might know something about the file's contents that
can help it determine whether the file complete, or you might decide
(somewhat arbitrarily) that a file that hasn't grown in the last X
seconds is complete. You might also use a secondary channel through
which the uploader can tell you the status of uploaded files.
I think the best general solution is to upload to a temporary
filename. The uploading process can then rename the file once the
upload is complete.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Pafo007 - 15 Mar 2007 18:03 GMT
An other way is to read the length of the file, wait a couple of seconds
and then read it another time. If the sizes are equal, download may have
finished... But the lag may induce some mistake.