So when I try to submit this code I get the following error:
Error in com/codegym/task/task31/task3105/Solution.java on line 34
cannot find symbol
symbol: method readAllBytes()
location: variable zipIs of type java.util.zip.ZipInputStream
Anyone an idea what I'm doing wrong?
package com.codegym.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 fileToBeAdded = args[0];
String zipArchive = args[1];
Map<String, Path> savedFiles = saveFilesInMap(zipArchive);
createArchive(savedFiles, fileToBeAdded, zipArchive);
}
public static Map<String, Path> saveFilesInMap(String archive) throws IOException {
Map<String, Path> map = new HashMap<>();
FileInputStream fis = new FileInputStream(archive);
ZipInputStream zipIs = new ZipInputStream(fis);
ZipEntry ze;
while ((ze = zipIs.getNextEntry()) != null) {
Path tempFile = Files.createTempFile("","");
Files.write(tempFile, zipIs.readAllBytes());
map.put(ze.getName(), tempFile);
}
zipIs.close();
fis.close();
return map;
}
public static void createArchive(Map<String, Path> files, String fileToBeAdded, String archiveName) throws IOException {
FileOutputStream fos = new FileOutputStream(archiveName);
ZipOutputStream zos = new ZipOutputStream(fos);
files.forEach((name, path) -> {
try {
zos.putNextEntry(new ZipEntry(name));
Files.copy(path, zos);
} catch (IOException e) {
e.printStackTrace();
}
});
zos.putNextEntry(new ZipEntry("new/" + fileToBeAdded));
Files.copy(Paths.get(fileToBeAdded), zos);
zos.close();
fos.close();
}
}