I am trying to create a very simple account system where a user can create an account and "login" to an account that they have created. At the moment after the user inputs their details I add the account to a text file like so;
public void createAccount(UserInfo createdUser) throws FileNotFoundException, IOException{
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("auctionAccounts.txt"));
objectOutputStream.writeObject(createdUser);
objectOutputStream.flush();
objectOutputStream.close();
}
I have now moved onto the "login" method, and I am struggling to find a way to loop through the objects stored in the textfile to see if an account exists. I just want to do a very simple compare such as;
if(enteredUsername == textfile.username){
if(enteredPassword == textfile.password){
//Do something
}
}
Obviously that is the simple pseudo code, I am teaching myself Java and haven't come across a way to loop through a text file at the moment. I understand that I could probably use an ArrayList of accounts, but I would like it if when the user comes back to my program after exiting their account would still exist.
Many thanks