Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

How to Know Whether a File is "Complete"?

Thread view: 
E11 - 14 Mar 2007 08:28 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.