package com.codegym.task.task31.task3110;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.nio.file.Paths;
import com.codegym.task.task31.task3110.command.Command;
import com.codegym.task.task31.task3110.exception.PathNotFoundException;
import com.codegym.task.task31.task3110.exception.NoSuchZipFileException;
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()];
}
}
Pls help.
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
7 October 2020, 15:26
#1 lines 63-64 should be uncommented
#2 line 68 should be inside the while loop, right before it ends a cycle.
+2
Youngsan
7 October 2020, 17:28
I tried, but still failed to be verified.
#1 lines 63-64 should be uncommented. - No difference.
#2 line 68 should be inside the while loop, right before it ends a cycle. - Tried in while loop, but failed.
I don't understand, but something is wrong. I found exactly same sources through web surfing, seemed to be verified. Thanks.
0
Banak
21 November 2021, 20:35
the try-with-resources closes the zipInputStream. I think you don't need to close it at the end.
0