На домашнем все прекрасно работает. Если файла нет добавляется, если есть перезаписывается.
package com.javarush.task.task31.task3105;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.*;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/*
Добавление файла в архив
*/
public class Solution {
public static void main(String[] args) throws IOException {
// 1
String name0 = args[0];
String name1 = args[1];
String name2 = ("new" + "/" + Paths.get(args[0]).getFileName().toString());
FileInputStream inputStream = new FileInputStream(Paths.get(name1).toString());
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
Map<String, byte[]> streamMap = new LinkedHashMap<>();
ZipEntry zipEntry;
String name;
int b;
byte[] buffer = new byte[8192]; //без буфера ошибка времени выполнения
while (( zipEntry = zipInputStream.getNextEntry()) != null) {
if (!zipEntry.getName().equals(name2)) {
name = zipEntry.getName();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
while (( b = zipInputStream.read(buffer)) != -1) {
stream.write(buffer, 0 , b);
}
stream.flush();
byte[] bytes = stream.toByteArray();
stream.close();
streamMap.put(name, bytes);
zipInputStream.closeEntry();
}
}
zipInputStream.close();
inputStream.close();
// 2
FileOutputStream outputStream = new FileOutputStream(Paths.get(name1).toString());
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
// 3
ByteArrayOutputStream buf = new ByteArrayOutputStream();
Files.copy(Paths.get(name0), buf);
streamMap.put(name2, buf.toByteArray());
buf.close();
for (Map.Entry<String, byte[]> entry : streamMap.entrySet()) {
ZipEntry zipEntry2 = new ZipEntry(entry.getKey());
zipOutputStream.putNextEntry(zipEntry2);
zipOutputStream.write(entry.getValue());
zipOutputStream.closeEntry();
}
zipOutputStream.close();
}
}