Пробывал писать все содержимое сразу, и сначала в папку new потом все остальное, но не проходит.
package com.javarush.task.task31.task3105;
import sun.font.FontRunIterator;
import java.io.*;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
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 {
// args = new String[2];
// args[0] = "C:/result.mp3";
// args[1] = "C:/pathToTest/test.zip";
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(args[1]));
Map<ZipEntry, String> data = new HashMap<>();
String s = "";
ZipEntry entry;
int a;
while ((entry = zipIn.getNextEntry()) != null){
while((a = zipIn.read()) != -1) {
s += a + " ";
}
data.put(entry, s);
s = "";
zipIn.closeEntry();
}
zipIn.close();
FileOutputStream zipFile = new FileOutputStream(args[1]);
ZipOutputStream zip = new ZipOutputStream(zipFile);
ZipEntry tempEntry = new ZipEntry("new/" + Paths.get(args[0]).getFileName().toString());
zip.putNextEntry(tempEntry);
Files.copy(Paths.get(args[0]), zip);
// FileInputStream reader = new FileInputStream(args[0]);
// while (reader.available() > 0){
// s += String.valueOf(reader.read()) + " ";
// }
// reader.close();
// data.put(new ZipEntry("new/" + args[0].substring(args[0].lastIndexOf("/") + 1)), s);
for(Map.Entry<ZipEntry, String> pair : data.entrySet()){
// System.out.println(pair.getKey() + " - " + pair.getValue());
File file = Files.createTempFile("temp-" + pair.getKey().toString().substring(pair.getKey().toString().lastIndexOf("/")+1), ".tmp").toFile();
FileOutputStream fos = new FileOutputStream(file);
String[] sS = pair.getValue().split(" ");
byte[] b = new byte[sS.length];
for (int i = 0; i <b.length ; i++) {
b[i] = Byte.parseByte(sS[i]);
}
fos.write(b);
fos.close();
if(!pair.getKey().toString().equals(tempEntry.toString())){
zip.putNextEntry(pair.getKey());
Files.copy(file.toPath(), zip);
}
}
zip.close();
zipFile.close();
}
}