• 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!