На практике всё красиво работает. Валидатор не хочет принимать. Что ему ещё нужно?
package com.javarush.task.task31.task3105;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
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 {
ZipEntry tmpEntry;
ZipInputStream zipI = new ZipInputStream(new FileInputStream(args[1]));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte buffer[] = new byte[8048];
Path file = Paths.get(args[0]);
String newZipEntry = "new/" + file.getFileName();
Map<String, byte[]> map = new HashMap<>();
while((tmpEntry = zipI.getNextEntry()) != null){
if (!tmpEntry.getName().equals(newZipEntry)){
byteArrayOutputStream.write(buffer, 0 , zipI.read(buffer));
map.put(tmpEntry.getName(),byteArrayOutputStream.toByteArray());
byteArrayOutputStream.reset();
}
}
byteArrayOutputStream.close();
zipI.close();
ZipOutputStream zipO = new ZipOutputStream(new FileOutputStream(args[1]));
zipO.putNextEntry(new ZipEntry(newZipEntry));
Files.copy(file, zipO);
for (Map.Entry<String, byte[]> entry : map.entrySet()){
zipO.putNextEntry(new ZipEntry(entry.getKey()));
zipO.write(entry.getValue());
}
zipO.close();
}
}