• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stop reading when reached the end of file  RSS feed

 
James Oh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
James Oh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!