Re: Project5Read
rossum wrote:
Clunky, but it looks like the only way to do it. Ugh. Now I know why
I usually use text streams rather than data streams.
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.
try {
try {
int counter = 0;
String empName = istream.readUTF();
catch( EOFException() )
System.out.println( "At EOF." );
// might want to log this too, for debugging.
}
try {
String dept = istream.readUTF();
int numVacaDays = istream.readInt();
empName = istream.readUTF();
System.out.println("The Employee's Number is: " +
counter);
System.out.println("The Employee's Name is: " + empName);
System.out.println("The Employee's Department is: " +
dept);
System.out.println("The Employee has " + numVacaDays + "
Vacation Days Available");
++counter;
System.out.println("The total number of Employees is: " +
counter);
} catch (EOFException e) {
throw new RuntimeException( e );
}
} finally {
istream.close();
ostream.close();
}