public void removeFiles(List<Path> pathList) throws Exception{ if(!Files.notExists(zipFile)) throw new NoSuchZipFileException(); Path tempFile = Files.createTempFile(zipFile.getParent(),"tempFile", ".zip"); try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFile))){ ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { if(pathList.contains(Paths.get(zipEntry.getName()))) { ConsoleHelper.writeMessage("Removed this file " + zipEntry.getName()); continue; } else { try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(tempFile))) { zipOutputStream.putNextEntry(new ZipEntry(zipEntry.getName())); copyData(zipInputStream, zipOutputStream); zipOutputStream.closeEntry(); } } zipEntry = zipInputStream.getNextEntry(); } Files.move(tempFile, zipFile, StandardCopyOption.REPLACE_EXISTING); } } public void removeFile(Path path) throws Exception { removeFiles(Collections.singletonList(path)); }