Meaningless Drivel is fun!
The moose likes I/O and Streams and the fly likes zip files without path info... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "zip files without path info..." Watch "zip files without path info..." New topic

zip files without path info...

Eric Martin

Joined: Jul 15, 2005
Posts: 22
I don't know if this is the best board for the question, but I am trying to do this from a servlet, so...

I am using ZipOutputStream to create zip file containing 3 files on our server. I don't want to files to be inside directories when they are zipped, so how do I add them without the path information?

The 3 filenames all include the full server path to the file and they are getting added to the archive inside a directory structure that matches the server path.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63839

Moved to the I/O forum.

[Asking smart questions] [About Bear] [Books by Bear]
Rajagopal Manohar
Ranch Hand

Joined: Nov 26, 2004
Posts: 183
just guessing

try changing

// Add ZIP entry to output stream.
zos.putNextEntry(new ZipEntry(filenames[i]));


Eric Martin

Joined: Jul 15, 2005
Posts: 22
Thanks! I was able to get it working with the following changes:

The ZipEntry is what controls how it is represented in the zip file.

[ December 13, 2005: Message edited by: Eric Martin ]
I agree. Here's the link:
subject: zip files without path info...
It's not a secret anymore!