zip
hi,
i am trying to figure out why is it that whenever i try to zip files, i get the whole structure included. e.g i have a file in C:/folder/folder/folder/1.file
when i zip using this function, i get the zip file which has folders -->
folder
|__folder
|__folder
|_1.file
i want to get just 1.file in the zip. how can i do this? thanks
publicint zip(){
byte[] buffer =newbyte[16384];
// Specify zip file name
String zipFileName = destFold +"/" + genRand +".zip";
try{
ZipOutputStream out =
new ZipOutputStream(new FileOutputStream(zipFileName));
// Set the compression ratio
out.setLevel(Deflater.DEFAULT_COMPRESSION);
// iterate through the array of files, adding each to the zip file
for (int i = 0; i < arrayFiles.size(); i++){
// Associate a file input stream for the current file
FileInputStream in =new FileInputStream((String)arrayFiles.get(i));
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry((String)arrayFiles.get(i)));
// Transfer bytes from the current file to the ZIP file
//out.write(buffer, 0, in.read(buffer));
int len;
while ((len = in.read(buffer)) > 0)
{
out.write(buffer, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
}
catch (Exception e)
{
e.printStackTrace();
errlog(e.getMessage());
return -1;
}
return 0;
}

