aspose file tools*
The moose likes Java in General and the fly likes Windows XP Compressed Folders doesn't recognize my Java-created zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Windows XP Compressed Folders doesn Watch "Windows XP Compressed Folders doesn New topic
Author

Windows XP Compressed Folders doesn't recognize my Java-created zip file

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I can't find a solution for this anywhere! I'm creating a .docx file (a Microsoft Office XML file, which is simply a zip file with certain directories and files in it). My zip files created with Java's ZipOutputStream class are being opened just find on Mac OS X, and I tried changing the file separator to a couple different things, but Windows XP is still complaining that my generated zip file (which I'm leaving with a .zip extension for now) is invalid or corrupted and won't open it. However, Winzip will open it on Windows. That won't work for my users, though, because I need Microsoft Office 2007 to be able to automatically open these files.

Before, I was using the Apache Commons VFS, but now I've reverted to simple examples just to try to get a basic case working. Windows opens my generated zip file just fine as long as there are no subdirectories, but I must have subdirectories, and I can't find a way to get Windows Compressed Folders to play nice whenever I try to include files in subdirectories.

Here are 2 bits of sample code. The first one generates a zip file that Win XP Compressed Folders won't even open, but the second one opens even though it doesn't have the "subdirectory" zip entry in it. Does anyone know why?






Here's the one that generates a zip file that Win XP Compressed Folders can actually open:




The resulting zip file is 38 KB, but if I comment out the files String array and only insert the one file, the file size is 21 KB, so it seems like the file is being inserted, but Windows is not recognizing the one coming from the subdirectory. Any ideas?
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Wow, all I had to do in that ZipIt class was remove the initial forward slash from the ZipEntry name:

String[] files = new String[] {"D:/stylessub/styles.xml", "D:/document.xml"};
String[] entryName = new String[] {"stylessub/styles.xml", "document.xml"};


Awesome. Thanks to a Python programmer:

http://bytes.com/topic/python/answers/492744-script-make-windows-xp-readable-zip-file


Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1768
    
    7

This is actually part of the PKZIP file specification, so it's not specific to how Windows (XP) handles ZIP compressed archives:


file name: (Variable)

The name of the file, with optional relative path.
The path stored should not contain a drive or
device letter, or a leading slash. All slashes
should be forward slashes '/' as opposed to
backwards slashes '\' for compatibility with Amiga
and UNIX file systems etc.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I thought I'd post my complete solution for posterity's sake. Pardon me for the code formatting being off.

My goal was to create Microsoft Office files on Google App Engine for Java, and since some of the the tried-and-true libraries for writing the old binary Word and Excel formats (such as Apache POI) aren't currently supported on GAE, I decided to try to create the relatively new .docx and .xlsx formats.

You can read the whole story here:
http://stephenhuey.wordpress.com/2010/01/01/docxgae/

The most relevant bit of the code is below. Note that I'm using the GaeVFS library which is on top of the Commons VFS library. I had to do that since the usual File class isn't supported on GAE.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Windows XP Compressed Folders doesn't recognize my Java-created zip file