Код: Выделить всё
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String email;
while (true) {
System.out.print("Please enter your email address: ");
email = sc.nextLine();
// isValid method in the Validation.java file is used for validation
if (Validation.isValidEmail(email)) {
break;
} else {
System.out.println("Invalid email format! Please try again.");
}
}
// Based on the user's email we will check if they already have an account
// If they do, we will exit the process
if (User.getUserEmail(email)) {
System.out.println("You already have an account, Login!");
}
}
public static boolean getUserEmail(String email) {
File userDetails = new File("UserDetails.txt");
try (Scanner reader = new Scanner(userDetails)) {
while (reader.hasNextLine()) {
if (userDetails.canRead() && reader.nextLine().equals(email)) {
return true;
}
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return false;
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... -from-file
Мобильная версия