I think this is a pretty simple question. I have a group of text files archived into a zip file. The zip file seems to be valid and uncorrupted because I can unzip and zip it at will from the command line with no problem. Ultimately, I would like to unzip this file into a specified directory. As a first step, I am trying to construct a new ZipFile object (in java.util.zip.*) for this file using the following line of code:
where name is a javaString holding the fully resolved name of the zip file. The problem is that this command throws "java.util.zip.ZipException: error in opening zip file".
I have also tried the following:
The File object is constructed okay, but then I get the same exception when I try to construct the ZipFile object. I've searched this and other forums about similar problems with the ZipFile class, but most of them seem to be more complicated than this simple problem, involving JARs and deployment of apps.
Any ideas about what could be causing this would be greatly appreciated.
You are right. Please forget about my last comment. It was all wrong.
For your original problem, can you please elaborate how exactly did you make the zip file. Especially, is there a chance that any app-specific algorithm was used for compression, as opposed to the standard zip algorithm?
Also, try to debug within ZipFile class and check which code throws this ZipException in your case.
Thanks very much for following up on this. I am still completely stuck, but I also haven't been able to give it as much attention for the last 24 hours as I would have liked.
Yes, I used the command line zip command on Mac OS X. I don't know how standard that utility is, but I do know that WinZip can unzip the the same file when I copy it to Windows XP and I can unzip it on the two flavors of Linux I have tried (CentOS and Fedora Core 10 so far). The other piece of information I have about this utility is the man page for the Mac OS X zip utility, which says "zip is a compression and file packaging utility for Unix, VMX, MSDOS, OS/2, Windows 9x/NT/XP, Minix, Atari, Macintosh, Amiga, and Acorn RISC OS. It is analogous to a combination of the Unix commands tar and compress and is compatible with PKZIP (Phil Katz's ZIP for MSDOS systems)."
I used the recursive flag to make the file because I am zipping an entire directory with a couple thousand files in that directory. The directory name is "cempart" and the exact command I use to do the zip is: zip -r cempart.zip cempart
I thought that the recursive flag might be the problem, so as a test I just zipped two files together like this: zip test.zip fileA fileB
But even this simple zip file throws the same ZipException. When I run my code in debug mode within Netbeans, I try to step into the ZipFile constructor to see where the exception is thrown, as you suggested, but the exception is thrown immediately. I never get inside the ZipFile constructor at all. It is strange; maybe I am using the debugger incorrectly in this case, but I have had good luck stepping into Java functions before this.