如果电子邮件已经存在,我想读取文件,但是如果不将其写入文件,则什么也不做。
private void readEmail(String file, Email emails) {
try (FileInputStream fileInputStream = new FileInputStream(file)) {
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
Email email;
while ((email = (Email) objectInputStream.readObject()) == null || (email = (Email) objectInputStream.readObject()) != null) {
if(!emails.getEmail().equals(email)){
writeInFile(file, emails);
}else{
System.out.println("User already exist!");
}
}
objectInputStream.close();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}