I have a method to check if an account number is present within a list of numbers in a file. It can be executed multiple times. However, I need to read the file from the start each time, so the scanner needs to be reset somehow. Is this the best way to do it?
.
public static boolean verifyAccount(int accountNum)
{
boolean valid = false;
while (file.hasNextInt())
if (accountNum == file.nextInt())
valid = true;
/*Reset Scanner to beginning of file*/
file.close();
try
{
file = new Scanner(new File("VALID ACCOUNTS.TXT"));
}//end try
catch (FileNotFoundException e)
{
System.err.println("ERROR: VALID ACCOUNTS.TXT could not be found");
}//end catch
return valid;
}//end verifyAccount