У меня все проходит, все файлы сохраняются насколько я могу видеть, не знаю в чем проблема,
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 {
/* String[] args = new String[2];
args[0] = "C:/JavaRushTasks/test/G.txt";
args[1] = "C:/JavaRushTasks/test/C.zip";
*/
HashMap<String, byte[]> map = new HashMap<>();
Path path = Paths.get(args[0]);
ZipInputStream zip = new ZipInputStream(new FileInputStream(args[1]));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ZipEntry zipEntry = zip.getNextEntry();
while (zipEntry != null) {
if(("new/" + path.getFileName()).equals(zipEntry.getName())){
zip.closeEntry();
zipEntry = zip.getNextEntry();
}else{
byte[] s = new byte[6400];
int i;
while ((i = zip.read(s)) > 0) {
stream.write(s, 0, i);
}
map.put(zipEntry.getName(), stream.toByteArray());
zipEntry = zip.getNextEntry();
}
}
zip.closeEntry();
zip.close();
stream.close();
/*
you need to copy data directly into outpitstream by caling Files.copy
FileInputStream fileInputStream = new FileInputStream(path.toString());
byte[] s = new byte[(int) Files.size(path)];
while (fileInputStream.available() > 0) {
fileInputStream.read(s);
}
fileInputStream.close();
map.put((Paths.get("new").resolve(path.getFileName())).toString(), s);
*/
//Path newFile = (Paths.get("new").resolve(path.getFileName()));
FileOutputStream file = new FileOutputStream(args[1]);
ZipOutputStream zipOutputStream = new ZipOutputStream(file);
ZipEntry fileZipEntry = new ZipEntry( "new/"+ path.getFileName());
zipOutputStream.putNextEntry(fileZipEntry);
Files.copy(path,zipOutputStream);
zipOutputStream.closeEntry();
for (Map.Entry<String, byte[]> entry : map.entrySet()) {
ZipEntry zipEntry1 = new ZipEntry(entry.getKey());
zipOutputStream.putNextEntry(zipEntry1);
zipOutputStream.write(entry.getValue());
zipOutputStream.closeEntry();
}
zipOutputStream.close();
}
}