aspose file tools
The moose likes Java in General and the fly likes check if file creation or transfer is complete Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "check if file creation or transfer is complete" Watch "check if file creation or transfer is complete" New topic
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
    
    2

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
    
    2

Very unlikely. In non-Windows environments you can even delete a file which is being written to by another application.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: check if file creation or transfer is complete
 
Similar Threads
Copy/moving a file from one location to Server location.
Nest the selectOneRadio Under the selectManyCheckbox
Transfering files from one Linux System to another
fileset(erroronmissingdir) tag in ant
XML Web Service response -- maximum size?