ZIPPING IN JAVA WITHOUT PATH STORE

V

valerie.en.davy

Hello,

I've searched the API's but didn't see anything about the following
problem : I'm using java.util.zip to create a zip file containig some
xmls. No trouble creating the zip but when opening it, I see the files
all have the folder structure of the location(where the xmls were)
and where I made the zip file. To avoid this in winrar I normaly
chose in options the "do not store path" option. Can I do this in
java?

TIA, D


private void zip (){

File[] xmls = getFileArray(BASE_PREFIX, XML_EXTENTION);

byte[] buf = new byte[1024];

try {

String outFilename = OUTPUTZIP;
ZipOutputStream out = new ZipOutputStream(new
FileOutputStream(BASEDIR + SLASH + nbrTreated + outFilename));


for (int i=0; i<xmls.length; i++) {

String filename = BASEDIR + SLASH + xmls.getName();

FileInputStream in = new FileInputStream(filename);

out.putNextEntry(new ZipEntry(filename));

int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}

out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
 
V

valerie.en.davy

Never mind guys,

my mistake : in the ZipEntry I also used the full path filename
instead of only the name it self. Works fine now..




FileInputStream in = new FileInputStream(BASEDIR +
SLASH + xmls.getName());
out.putNextEntry(new
ZipEntry(xmls.getName()));
 

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

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top