public class Solution { public static void main(String[] args) throws IOException { Map<String, ByteArrayOutputStream> map = new HashMap<>(); try (ZipInputStream zip = new ZipInputStream(new FileInputStream(args[0]))) { ZipEntry zipEntry; while ((zipEntry = zip.getNextEntry()) != null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int count = 0; while ((count = zip.read(b)) != -1) { output.write(b, 0, count); } map.put(zipEntry.toString(), output); zip.closeEntry(); } } // // // try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(args[1]))) { String fileName = args[0].substring(args[0].lastIndexOf(File.separator) + 1); ZipEntry zipka = new ZipEntry("new/" + fileName); zipOutputStream.putNextEntry(zipka); Files.copy(Paths.get(args[0]), zipOutputStream); zipOutputStream.closeEntry(); // // // for (Map.Entry<String, ByteArrayOutputStream> pair : map.entrySet()) { ZipEntry zip9275 = new ZipEntry(pair.getKey()); if (!zip9275.toString().endsWith(fileName)) { zipOutputStream.putNextEntry(zip9275); zipOutputStream.write(pair.getValue().toByteArray()); zipOutputStream.closeEntry(); } } } } }