| Author |
check if file creation or transfer is complete
|
manish ahuja
Ranch Hand
Joined: Oct 23, 2003
Posts: 312
|
|
Hi there,
I wanted to check if there is a way to figure out a file inside a directory is complete and not partial i.e in the process of being generated. There is an external process which transfers the file to a certain directory. Another process periodically checks the directory for files and reads it when it finds a new one. I don't want the read process to start reading while the file transfer process is still underway.
Is there a way to detect if a file transfer process was complete.
Let me know your thoughts.
Thanks.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
Just a guess:
Check the file size, wait a couple of seconds, check the file size again. If it is the same; done.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
That won't work properly if the writing (temporarily) hangs for whatever reason.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
The short answer to the question is "No".
The usual solution (for those who require some sort of reliable solution) is for the application which is producing the file to send some kind of explicit signal saying it's complete. For example moving the completed file into some other directory, or changing its name to something which the receiver is looking for, or creating another file (this one empty) with a related filename.
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8441
|
|
|
I wonder if the canWrite() will return false if the file is being written to by another application? Too early for me to put together a test code. Maybe later.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Very unlikely. In non-Windows environments you can even delete a file which is being written to by another application.
|
 |
 |
|
|
subject: check if file creation or transfer is complete
|
|
|