wood burning stoves*
The moose likes I/O and Streams and the fly likes Copying file issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Copying file issue." Watch "Copying file issue." New topic
Author

Copying file issue.

Hisouka Devera
Greenhorn

Joined: Oct 16, 2012
Posts: 28
Good Day,

I have a 2 module which is run in parallel, the first one is writing a file in directory temp, and the other one is copying file from temp to some directory.

The problem is that, there is an instance that the copy module copies the file while its not yet done writing by the writing module.

Example: writing module suppose to write a 1MB file, but the copy module is copying it while the file is not yet done (20KB).

How can we prevent this?

Regards
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Why are the pieces of code run in parallel when clearly they should run sequentially?


Ping & DNS - my free Android networking tools app
Hisouka Devera
Greenhorn

Joined: Oct 16, 2012
Posts: 28
there is a reason behind it. One reason is if they dont want to run the copy module.

Any idea sir?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Well, it doesn't really matter what the reason is, you can't copy a file while it is still being created, so that needs to change.

they dont want to run the copy module.

That being the case, why *is* the copy module run, especially if that causes a problem?
Hisouka Devera
Greenhorn

Joined: Oct 16, 2012
Posts: 28
Is there any function that will not allow to copy a file while file is using by other process?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
I don't think so. Your code needs to keep track of which files are for copying, and which are not. Or, to keep it simple, the file creation process can notify the file copy process of which files are ready for copying. A java.util.concurrent.BlockingQueue might work for that.
Hisouka Devera
Greenhorn

Joined: Oct 16, 2012
Posts: 28
Thanks a lot for the idea.. Appreciate it a lot. I will try it.
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 162

I so in many different companies using the file name (or extension or moving it between folders) as a way to makr a status of the current file, liek processing and done. In this solution, the other program/thread/etc would just watch more specificy files (or folder), removing any problem with concurrency


Please, visit me for some cool tech post at www.ourdailycodes.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Copying file issue.
 
Similar Threads
Ho to modify a file through java?
Writing a new line character
how to insert a new line into a file using buffered writer?
Copying picture files
I Passed - Thanks Everyone!