Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing a file in the middle of creating it.  RSS feed

 
Rudy Rusli
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a basic console-based JAVA program that creates a ZIP file in a HTTP folder for my clients to download.
My question is what's going to happen when in the middle of creating the zip file, my clients try to access the ZIP file. Will they get incomplete file?

Thanks in advance for all the advice.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummmm... yes?

If this is a concern, give the file a temporary name (WORKING.TMP) while you're writing it, and rename it to WHATEVER.ZIP when you're done.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, they can't get the complete file if it isn't even there yet, now can they

That begs the question why you would allow clients to access a file that hasn't been created yet?
 
Rudy Rusli
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a JAVA program that will create a new zip file every 5 minutes.

My concern is not on the first iteration, but on the next iterations. The old zip file would be there. It could happen that the program is rewriting the zip file and then in the middle of that, my clients are accessing the zip file. This could lead to problem, right?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case not even Ernests approach would work, because it would disrupt the currently active download. I'd give the files distinctive names, and tell the clients to download the latest (or alphabetically highest). That can be automated easily.
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
Is there any method to check incomplete file or completed file?
I have same problem to rename incomplete file while being copy a big size file.

give me advice,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Eung JM", please check your private messages for an important administrative matter.

Also please do not repeat a question in more than one topic, and please don;t revive old topics.
[ July 31, 2008: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!