How to Know Whether a File is "Complete"?

Discussion in 'Java' started by E11, Mar 14, 2007.

  1. E11

    E11 Guest

    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
    E11, Mar 14, 2007
    #1
    1. Advertising

  2. E11

    Guest

    On 3ÔÂ14ÈÕ, ÏÂÎç3ʱ28·Ö, "E11" <> 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
    , Mar 14, 2007
    #2
    1. Advertising

  3. 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
    Gordon Beaton, Mar 14, 2007
    #3
  4. E11

    Pafo007 Guest

    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.
    Pafo007, Mar 15, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?eXVjaGFuZw==?=
    Replies:
    1
    Views:
    1,691
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Apr 8, 2006
  2. nan
    Replies:
    4
    Views:
    381
    Dan Pop
    Dec 5, 2003
  3. Anonymousgoogledeja

    how can i Know whether atoi function call succeed?

    Anonymousgoogledeja, Aug 22, 2005, in forum: C Programming
    Replies:
    15
    Views:
    962
    Jack Klein
    Aug 23, 2005
  4. r.z.
    Replies:
    2
    Views:
    426
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    215
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page