Creating a zip or jar file with directory structure!

L

Lee

Hi,

I am trying to (zip or jar) a directory (including empty directories)
using
java.util.zip.* and java.util.jar.*. I can create zip and jar files
but
when extracted all files appear to be in the root dir of the extracted
zip/jar. How can i keep the directory structure intact? Does anyone
have
any examples please?

thanks in advance
lee
 
R

Roedy Green

I am trying to (zip or jar) a directory (including empty directories)
using
java.util.zip.* and java.util.jar.*. I can create zip and jar files
but
when extracted all files appear to be in the root dir of the extracted
zip/jar. How can i keep the directory structure intact? Does anyone
have
any examples please?
see http://mindprod.com/jgloss/zip.html
 
T

Thomas Kellerer

I am trying to (zip or jar) a directory (including empty directories)
using
java.util.zip.* and java.util.jar.*. I can create zip and jar files
but
when extracted all files appear to be in the root dir of the extracted
zip/jar. How can i keep the directory structure intact? Does anyone
have
any examples please?

Are you sure this is not a problem with your method of unzipping the files?

Thomas
 
I

impaler

Lee said:
Hi,

I am trying to (zip or jar) a directory (including empty directories)
using
java.util.zip.* and java.util.jar.*. I can create zip and jar files
but
when extracted all files appear to be in the root dir of the extracted
zip/jar. How can i keep the directory structure intact? Does anyone
have
any examples please?

thanks in advance
lee

Check what Roedy Green has on that great site and as Thomas said check
your unzipping. Check the zip with a 3rd party app (a simple win
explorer will do it) and make sure you don't have the directory
structure there. If everything seems all right, check when adding the
new entry to the ZipOutputStream. It has to contain the full path you
want to see inside the zip file.

for ex:
....
ZipOutputStream zos = new ZipOutputStream(new
FileOutputStream("/test.zip"));
File f = new File("pathToMyFileToBeZipped");
//add zip entry to output stream
zos.putNextEntry(new ZipEntry(f.getAbsolutePath()));
....

use the absolute path, if you want a relative path you will do a
substring on the absolutepath and there you go
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top