By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

Problem Saving Zip Files (Only Shows on WinXP for NOw)

P: n/a
I am using OpenOffice files in my app. They're stored in .zip format, so
the zip format is much more important, in this case, than that they're OOo
files (other than that the extension is .sxw and not .zip).

(I know these code sections use outside variables, but it's probably pretty
clear what the outside variables are -- if not, I can clarify.)

I read the files in this way:
int i = 0;
byte[] bIn = new byte[4096], bData;
LinkedList llEntry = new LinkedList();
inFile = s; outFile = s;
try {
ByteArrayOutputStream bBuffer;
ZipInputStream zin = new ZipInputStream(new FileInputStream(inFile));
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
bBuffer = new ByteArrayOutputStream();
bData = new byte[0];
while ((i =, 0, 4096)) != -1) {
bBuffer.write(bIn, 0, i);
bData = bBuffer.toByteArray();
} catch (Exception e) {//Error handling routine here}

And that works fine. Then, throughout the program, I take one entry in the
archive, edit it, then when I save, I save it all with the one changed

byte[] bBuffer = null;
int i = 0;
String sName = "";
ZipEntry entry;
try {
ZipOutputStream zon = new ZipOutputStream(new FileOutputStream(outFile));
for (i = 0; i < aEntry.length; i++) {
entry = new ZipEntry(aEntry[i]);
bBuffer = (byte[]) llData.get(i);
zon.write(bBuffer, 0, bBuffer.length);
LDFile.setFilePermission(outFile, "777");
} catch (Exception e) {//Error trapping here}

This tested perfectly on a Linux system, works perfectly on several Win2k
systems, and works fine on one WinXP system. One XP system, however, has
problems. I don't know if the problems are in XP itself, or not. I talked
with a friend who said the problem is that XP can handle archives on its
own, and it's corrupting it by trying to handle the archive itself. Can XP
tell this is an archive when I'm writing it out?

Only a few files (in proportion to the number created) are corrupted. All
the entries seem to be intact, but the problem seems to be in the format of
the zip file (I opened a corrupt file in OOo, and it warned me, then
attempted to restore the document and was able to completely restore it).

So I have several questions:

1) Since I'm writing with a FileOutputStream, can the OS tell I'm writing an
archive? (I would not think so.)
2) Could the OS be interferring by trying to handle it as a .zip file on
it's own?
3) If "no" on 1 and 2, how is the archive being corrupted?
4) Would I be better off creating 2 Zip objects, one for the input, then
transfer ALL the entries to the new Zip object for writing out, so I'm
using a clean archive?

Thanks for any help, or ideas that might point me in a new direction!

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.