Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How to Know Whether a File is "Complete"? (http://www.velocityreviews.com/forums/t484124-how-to-know-whether-a-file-is-complete.html)

E11 03-14-2007 07:28 AM

How to Know Whether a File is "Complete"?
 
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 03-14-2007 09:14 AM

Re: How to Know Whether a File is "Complete"?
 
On 3月14日, 下午3时28分, "E11" <edwinlee...@gmail.com> wrote:
> 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


Gordon Beaton 03-14-2007 09:26 AM

Re: How to Know Whether a File is "Complete"?
 
On 14 Mar 2007 00:28:38 -0700, E11 wrote:
> 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

--
[ 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 03-15-2007 05:03 PM

Re: How to Know Whether a File is "Complete"?
 
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.


All times are GMT. The time now is 01:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.