Get your CodeRanch badge!*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
jQuery in Action, 2nd edition
 
subject: correct way to read an object file
 
Similar Threads
Optimal I/O operations in Java
Object Serialization
Limit concurrent threads; report successful execution; terminating hung threads
How to read and after write a video (or any binary file)
Map object through servlet?