Caricamento...// Questi sono i file da includere nello zip
String[] filenames = new String[]{"filename1", "filename2"};
// Crea il buffer per leggere i file
byte[] buf = new byte[1024];
try {
// Crea il file zip
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
// Comprimi i file
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames[i]);
out.putNextEntry(new ZipEntry(filenames[i]));
// Trasferisci i bytes dal file al file zip
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Completa
out.closeEntry();
in.close();
}
// Completa il file zip
out.close();
} catch (IOException e) {
}
Lascia un commento
Copyright © 2005 - 2010 :: ianaz - created by Silvio Rainoldi