package com.project.common.utils.zip; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class ImageDownloader { public static void main(String[] args) throws IOException { File[] imageFiles = new File("images").listFiles(); if (imageFiles != null) { File zipFile = new File("images.zip"); FileOutputStream fos = new FileOutputStream(zipFile); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos); for (File imageFile : imageFiles) { if (imageFile.isFile()) { ZipArchiveEntry entry = new ZipArchiveEntry(imageFile.getName()); zos.putArchiveEntry(entry); FileInputStream fis = new FileInputStream(imageFile); byte[] buffer = new byte[1024]; int length; while ((length = fis.read(buffer)) != -1) { zos.write(buffer, 0, length); } fis.close(); zos.closeArchiveEntry(); } } zos.finish(); zos.close(); fos.close(); System.out.println("Images downloaded and packed into 'images.zip' successfully."); } else { System.out.println("No images found."); } } }