「java入門」複数ファイルを Zip に圧縮するサンプル

Javaコード
try {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outfilePath));
byte[] buffer = new byte[1024];
int len;

for(String file : files) {
InputStream in = new FileInputStream(file);
out.putNextEntry(new ZipEntry(file.getName()));
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
in.close();

}
out.close();

} catch(FileNotFoundException e){

} catch(Exception e){

}