Java EOFException

Associate
Joined
6 Dec 2007
Posts
2,103
Hey all, am getting the above exception in my uni project. Does it mean that it can't find the end of the text file that is being read in? And how do I sort it?

The offending code is:

while (anAccountNumber != "****" && activeAccounts < MAX_ACCOUNTS)
{
anAccountName = Text.readLine(accountsFileIn);
aBalance = Text.readDouble(accountsFileIn);

accountDetails [activeAccounts] = new BankAccount(anAccountNumber, anAccountName, aBalance);
activeAccounts++;
anAccountNumber = Text.readLine(accountsFileIn);
}

and:

public static void main ( String [] args ) throws IOException{
ATM anATM = new ATM();
anATM.bank.loadAccountDetails(ACCOUNT_FILENAME_IN);

}//main

If I'm being vague, please tell me and I will post more info. Thanks!
 
Ok thanks. I'm assuming that I need something in or near the above while loop to deal with it. Been having a play, and I'm not sure what direction to take. Any help would be massively appreciated :)
 
There's a lot of code - too much to post here, but basically it reads in two Strings (accountName and accountNo) and a double (balance). It is then supposed to terminate when an account number consisisting of 8x asterisks are read in from the text file.

The text file is:

12345678
T Jowell
270.50

34781234
T Blair
100.00

11112222
J Bloggs
250.00

44448888
L Hamilton
1200.00

22228888
G Brown
150.00

********
 
Last edited:
}

public void loadAccountDetails( String filename ) throws IOException
{

String anAccountNumber;
String anAccountName;
double aBalance;
String textFilesPath = "H:/";
BufferedReader accountsFileIn = Text.open(textFilesPath + filename);

activeAccounts = 0;
anAccountNumber = Text.readString(accountsFileIn);
while (anAccountNumber != "****" && activeAccounts < MAX_ACCOUNTS)
{
anAccountName = Text.readLine(accountsFileIn);
aBalance = Text.readDouble(accountsFileIn);

accountDetails [activeAccounts] = new BankAccount(anAccountNumber, anAccountName, aBalance);
activeAccounts++;
anAccountNumber = Text.readLine(accountsFileIn);
}

accountsFileIn.close();
sortAccountDetails();
}//loadAccountDetails

This be the bit that reads in the file :P
 
Thanks all! Case closed.

EDIT: or so I thought, now the bit of code to read in the data is giving me the EOF Exception, and the compiler blames this line:

aBalance = Text.readDouble(accountsFileIn);

Any ideas? And thanks all!
 
Last edited:
Back
Top Bottom