I've tried a bunch of methods but none are working
public void removeFiles(List<Path> pathList) throws Exception {
if(!Files.notExists(zipFile))
throw new NoSuchZipFileException();
Path tempFile = Files.createTempFile(zipFile.getParent(),"tempFile", ".zip");
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFile))){
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
if(pathList.contains(Paths.get(zipEntry.getName()))) {
ConsoleHelper.writeMessage("Removed this file " + zipEntry.getName());
continue;
}
else {
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(tempFile))) {
zipOutputStream.putNextEntry(new ZipEntry(zipEntry.getName()));
copyData(zipInputStream, zipOutputStream);
zipOutputStream.closeEntry();
}
}
zipEntry = zipInputStream.getNextEntry();
}
Files.move(tempFile, zipFile);
}
}
package com.codegym.task.task31.task3110;
import com.codegym.task.task31.task3110.exception.NoSuchZipFileException;
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 (NoSuchZipFileException e) {
ConsoleHelper.writeMessage("You didn't select an archive or you selected an invalid file.");
} catch (Exception e) {
ConsoleHelper.writeMessage("An error occurred. Please check the entered data.");
}
} while (operation != Operation.EXIT);
}
public static Operation askOperation() throws IOException {
ConsoleHelper.writeMessage("");
ConsoleHelper.writeMessage("Select an operation:");
ConsoleHelper.writeMessage(String.format("\t %d - Zip files into an archive", Operation.CREATE.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Add a file to an archive", Operation.ADD.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Remove a file from an archive", Operation.REMOVE.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Extract an archive", Operation.EXTRACT.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - View the contents of an archive", Operation.CONTENT.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Exit", Operation.EXIT.ordinal()));
return Operation.values()[ConsoleHelper.readInt()];
}
}