1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
public static void compress(String[] stFileName, String stZipFileName)
throws Exception
{
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(stZipFileName));
byte[] buf = new byte[1024];
// Compress the files
for (int i = 0; i < stFileName.length; i++)
{
FileInputStream in = new FileInputStream(stFileName[i]);
out.putNextEntry(new ZipEntry(stFileName[i]));
// Transfer bytes from the file to the ZIP file
int len;
while((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
} |