ошибка, код не для проверка, а для тестирования
File name: bbb.txt File size: 48
invalid entry compressed size (expected 30 but got 23 bytes)
bbb.txt [B@2e5d6d97
Process finished with exit code 0
вывод - zip файл содержит следующее
bbb.txt
/new/result.mp3
т.е. нет остальных 3 файлов
package com.javarush.task.task31.task3105;
import java.io.*;
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 zipFile = args[1];
String filePath = args[0];
// String zipFile = "C:/pathToTest/test.zip";
// String filePath = "C:/result.mp3";
String nameFile = filePath.substring(filePath.lastIndexOf("/") + 1); // обрезаем всё кроме result.mp3
HashMap <ZipEntry, byte[]> list = new HashMap<>();
byte bytes[] = null;
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
ZipEntry entry;
while((entry=zin.getNextEntry())!=null){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int c = zin.read(); c != -1; c = zin.read()) {
baos.write(c);
bytes = baos.toByteArray();
}
list.put(entry, bytes);
ZipOutputStream fout = new ZipOutputStream(new FileOutputStream(zipFile));
fout.putNextEntry(new ZipEntry("new/" + nameFile));
for (Map.Entry<ZipEntry, byte[]> entryW : list.entrySet()) {
fout.putNextEntry(entryW.getKey());
fout.write(entryW.getValue());
}
// fout.flush();
fout.close();
}
zin.closeEntry();
zin.close();
}
}