UPD: После исправления проверки на isRegular валик принял, но архивы со вложенностью всё равно не разбирает..
public void extractAll(Path outputFolder) throws Exception{
if(Files.notExists(zipFile))
throw new WrongZipFileException();
if(Files.notExists(outputFolder))
Files.createDirectories(outputFolder);
try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(zipFile))) {
ZipEntry entry;
while((entry = zis.getNextEntry()) != null){
Path path = outputFolder.resolve(entry.getName());
if (Files.notExists(path.getParent()))
Files.createDirectories(path.getParent());
try (OutputStream bos = Files.newOutputStream(path)) {
copyData(zis, bos);
}
zis.closeEntry();
}
}
}package com.javarush.task.task31.task3110;
import com.javarush.task.task31.task3110.exception.WrongZipFileException;
import java.io.IOException;
public class Archiver {
public static void main(String[] args) throws IOException {
Operation operation = null;
do {
try {
operation = askOperation();
CommandExecutor.execute(operation);
} catch (WrongZipFileException e) {
ConsoleHelper.writeMessage("Вы не выбрали файл архива или выбрали неверный файл.");
} catch (Exception e) {
ConsoleHelper.writeMessage("Произошла ошибка. Проверьте введенные данные.");
}
} while (operation != Operation.EXIT);
}
public static Operation askOperation() throws IOException {
ConsoleHelper.writeMessage("");
ConsoleHelper.writeMessage("Выберите операцию:");
ConsoleHelper.writeMessage(String.format("\t %d - упаковать файлы в архив", Operation.CREATE.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - добавить файл в архив", Operation.ADD.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - удалить файл из архива", Operation.REMOVE.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - распаковать архив", Operation.EXTRACT.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - просмотреть содержимое архива", Operation.CONTENT.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - выход", Operation.EXIT.ordinal()));
return Operation.values()[ConsoleHelper.readInt()];
}
}