How to Know Whether a File is "Complete"?

E

E11

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
 
R

rayzyang

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

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
 
G

Gordon Beaton

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
 
P

Pafo007

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top