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;

}

[2633 byte] By [clarenceloha] at [2007-11-27 2:06:57]
# 1
You don't say what arrayFiles is but, presumeably, it contains the "structure" you don't want. If they are filenames you will have you extract the "leaf" part of each name. (Files are a lot easier to work with than Strings.)
pbrockway2a at 2007-7-12 1:54:30 > top of Java-index,Java Essentials,Java Programming...
# 2
sorry to mention that arrayFiles contains the file locatione.g C:/folder/folder/folder/1.file
clarenceloha at 2007-7-12 1:54:30 > top of Java-index,Java Essentials,Java Programming...