• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

correct way to read an object file

 
Micah Wedemeyer
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wanted to know what the correct way to know when an object file has reached the end. Currently, I'm doing it like this:
<code>
try {
while (true) {
Object o = s.readObject();
choiceList.add(o);
}
}
catch (EOFException e) {
// Do nothing. It's reached the end of the file. This seems like the wrong way to handle this.
}
</code>
Is this the expected way to do it? It seems like a misuse of exceptions. Please let me know if there is a better way. I hate writing garbage code.
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
ObjectInputStream s = //get it somehow;
while (s.available() > 0) {
Object o = s.readObject();
choiceList.add(o);
}
</pre>
Geoffrey
------------------
Sun Certified Programmer for the Java 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic