Re: Project5Read
On Thu, 09 Jul 2009 16:03:46 -0700, markspace <nospam@nowhere.com>
wrote:
That's really awful. The problem is that it IS an error for the OP to
get an EOF anywhere but the first read. If he gets one while reading,
for example, the Name field, he should be throwing an error, not
swallowing it.
In this situation I would probably create an EmployeeRecord class and
a readRecord() method which returned a complete employee record if one
was available in the file, a null if there was no record available (a
normal EoF) and threw an IOException if the file ended in the middle
of a record:
int employeeCount = 0;
EmployeeRecord currentEmployee = null;
// Read first record
try {
currentEmployee = readRecord();
++employeeCount;
} catch (IOException ioe) {
System.err.println("First record read failed.");
currentEmployee = null;
}
// Read second and subsequent records
while (currentEmployee != null) {
processEmployee(currentEmployee);
try {
currentEmployee = readRecord();
++employeeCount;
} catch (IOException ioe) {
System.err.println("Record " + (employeeCount + 1) +
" read failed.");
currentEmployee = null;
}
}
I do not know how far the OP has got in his course so I have no idea
if this sort of thing has been covered yet.
rossum