while (true) {
try {
operation = askOperation();
if ((operation == Operation.EXIT)) {
break;
}
CommandExecutor.execute(operation);
} catch (WrongZipFileException e) {
ConsoleHelper.writeMessage("Вы не выбрали файл архива или выбрали неверный файл.");
} catch (Exception e) {
ConsoleHelper.writeMessage("Произошла ошибка. Проверьте введенные данные.");
}
}
Увидел ошибку, CommandExecutor.execute(operation); должен быть перед if ((operation == Operation.EXIT)) {
break;
}
Теперь так:
while (true) {
try {
operation = askOperation();
CommandExecutor.execute(operation);
if ((operation == Operation.EXIT)) {
break;
}
} catch (WrongZipFileException e) {
ConsoleHelper.writeMessage("Вы не выбрали файл архива или выбрали неверный файл.");
} catch (Exception e) {
ConsoleHelper.writeMessage("Произошла ошибка. Проверьте введенные данные.");
}
}
Но результат валидации прежний.
Странно, что принимает только через do/while. Почему?package com.javarush.task.task31.task3110;
import java.io.File;
import java.nio.file.Path;
public class test {
public static void main(String[] args) {
File file = new File("simpleFile.txt");
String fullPath = file.getAbsolutePath();
System.out.println(fullPath);
int startInd = fullPath.lastIndexOf("\\") + 1;
int endInd = fullPath.lastIndexOf(".");
String fileName = fullPath.substring(startInd, endInd);
System.out.println(fileName);
}
}