Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to Know Whether a File is "Complete"?

Reply
Thread Tools

How to Know Whether a File is "Complete"?

 
 
E11
Guest
Posts: n/a
 
      03-14-2007
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

 
Reply With Quote
 
 
 
 
rayzyang@gmail.com
Guest
Posts: n/a
 
      03-14-2007
On 3月14日, 下午3时28分, "E11" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      03-14-2007
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
 
Reply With Quote
 
Pafo007
Guest
Posts: n/a
 
      03-15-2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How can I know whether a file path is absolute or not ? Kyung won Cheon Ruby 1 08-06-2008 05:06 AM
how do I know whether .txt file is of char or wchar_t type? r.z. C++ 2 12-27-2006 09:58 PM
How to know whether success or not in FormView Control inserting. =?Utf-8?B?eXVjaGFuZw==?= ASP .Net 1 04-08-2006 03:48 AM
I know, I know, I don't know Andries Perl Misc 3 04-23-2004 02:17 AM



Advertisments