File sourcePath = new File(“testDirecory”);
FileInputStream fin = null;
FileOutputStream fout = null;
ZipOutputStream zout = null;
fout = new FileOutputStream("test.zip");
zout = new ZipOutputStream(new BufferedOutputStream(fout));
File[] sourceFiles = sourcePath.listFiles();
if(sourceFiles.length > 0){
byte[] buffer = new byte[1024*10];
int read;
for (int i = 0; i < sourceFiles.length; i++) {
fin = new FileInputStream(sourceFiles[i]);
ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName());
zout.putNextEntry(zipEntry);
while((read = fin.read(buffer)) != -1){
zout.write(buffer, 0, read);
}
fin.close();
zout.closeEntry();
}
FileInputStream fin = null;
FileOutputStream fout = null;
ZipOutputStream zout = null;
fout = new FileOutputStream("test.zip");
zout = new ZipOutputStream(new BufferedOutputStream(fout));
File[] sourceFiles = sourcePath.listFiles();
if(sourceFiles.length > 0){
byte[] buffer = new byte[1024*10];
int read;
for (int i = 0; i < sourceFiles.length; i++) {
fin = new FileInputStream(sourceFiles[i]);
ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName());
zout.putNextEntry(zipEntry);
while((read = fin.read(buffer)) != -1){
zout.write(buffer, 0, read);
}
fin.close();
zout.closeEntry();
}
zout.close();
}