This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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: 63227

Moved to the I/O forum.

[Asking smart questions] [Bear's FrontMan] [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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: zip files without path info...
It's not a secret anymore!