This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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.
 
author and iconoclast
Sheriff
Posts: 24218
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.
 
Rancher
Posts: 42975
76
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!