Все как всегда - все работает прекрасно. Валя не берет.
package com.javarush.task.task31.task3105;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class Solution {
static Map<String, byte[]> fileContent = new HashMap<>();
public static void main(String[] args) throws IOException {
reedZIP(args);
writeZip(args);
}
public static void reedZIP(String[] args) {
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(args[1]))) {
ZipEntry zipEntry;
while ((zipEntry = zis.getNextEntry()) != null){
String stopFileName = args[0].substring(args[0].lastIndexOf('/')+1);
if (!zipEntry.getName().equals(stopFileName) && !zipEntry.getName().equals("new/" + stopFileName) ) {
byte[] buffer = new byte[(int)zipEntry.getSize()];
int x;
while ((x = zis.read(buffer)) != -1){
fileContent.put(zipEntry.getName(), buffer);
}
}
zis.closeEntry();
}
}catch (Exception e){
}
}
public static void writeZip(String[] args){
try(ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(args[1]));
FileInputStream fis = new FileInputStream(args[0]);
) {
Path fileForDownloading = Paths.get(args[0]);
String pathToAdd = "new/" + args[0].substring(args[0].lastIndexOf('/')+1);
zos.putNextEntry(new ZipEntry(pathToAdd));
Files.copy(fileForDownloading, zos);
zos.closeEntry();
for(Map.Entry entry : fileContent.entrySet()){
ZipEntry zipEntry = new ZipEntry((String) entry.getKey());
zos.putNextEntry(zipEntry);
zos.write((byte[])entry.getValue());
zos.closeEntry();
}
}catch (Exception e){
}
}
}