Forums Register Login

Stop reading when reached the end of file

+Pie Number of slices to send: Send
I want to stop reading the file when it reaches the end of file.

My code looks like this.

public void fillUp() throws IOException {
int c = 1;
try {
while (c < this.size) {
next = rec.createObject();
next.readObject(dataSource);
if(next != null){
heap.put(next); // put the information just read
c = c + 1;
}else
break;
}
} catch (EOFException eof) {
}
heap.fixHeap(c);
}
even though I wrote break, it doesn't seem to work. What do I have to do to just stop reading and putting the information?
Thank you.

[ October 15, 2004: Message edited by: James Oh ]
[ October 15, 2004: Message edited by: James Oh ]
+Pie Number of slices to send: Send
The problem is likely in these 3 lines

In line 1 next is set to something (possibly null).
In line 2 the value of next is not changed and if it is null, exception is thrown (NullPointerException - if readObject() is not static) so the value of next can't be null when line 3 is executed and break statement is not reached.
[ October 15, 2004: Message edited by: Vlado Zajac ]
+Pie Number of slices to send: Send
Thank you.
next = rec.createObject(); is never null so I think it's line 2.
I'll try to fix it and if i can't i reply again.
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 956 times.
Similar Threads
Reading a SOAP Response/Handlers
Need hel;p: How to close a batch script from a java app.
translate to pig latin!? completely lost....
All data access methods need to be synchronized...
Probs w/ recent reinstall
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:55:19.