wood burning stoves*
The moose likes Java in General and the fly likes correct way to read an object file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "correct way to read an object file" Watch "correct way to read an object file" New topic
Author

correct way to read an object file

Micah Wedemeyer
Ranch Hand

Joined: Jun 11, 2001
Posts: 68
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

Joined: Aug 17, 2001
Posts: 171
    
    1
<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


Sun Certified Programmer for the Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: correct way to read an object file