exception - Why am I getting java.io.EOFException? -
exception - Why am I getting java.io.EOFException? -
this method read show details .ser file containing serialized objects of type show. method homecoming list gives exception before. why , how rid of it?
public list<show> populatedatafromfile(string filename) { list<show> shows=new arraylist<show>(); objectinputstream obj=null; seek { fileinputstream fin=new fileinputstream(filename); obj=new objectinputstream(fin); show show=null; while((show=(show) obj.readobject())!=null) { shows.add(show); show.getshowname(); } system.out.println(shows); } grab (ioexception e) { e.printstacktrace(); }catch(classnotfoundexception e) { e.printstacktrace(); }finally { seek { obj.close(); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } } homecoming shows; } the output is
java.io.eofexception @ java.io.objectinputstream$blockdatainputstream.peekbyte(objectinputstream.java:2571) @ java.io.objectinputstream.readobject0(objectinputstream.java:1315) @ java.io.objectinputstream.readobject(objectinputstream.java:369) @ com.util.datamanagerimpl.populatedatafromfile(datamanagerimpl.java:23) @ com.psl.client.main(client.java:9) show name: sahi re sahi show time: 6:30 pm seats available: 40 show name: ek shyam aapke naam show time: 6:30 pm seats available: 40 show name: moruchi maushi show time: 6:30 pm seats available: 40 show name: best show time: 6:30 pm seats available: 40 show name: naksharanche dene show time: 6:30 pm seats available: 40 the main method is
public static void main(string[] args) { datamanager dm=new datamanagerimpl(); list<show>shows=dm.populatedatafromfile("showdetails.ser"); // phone call functionalities here test code. for(show show:shows) { system.out.println("show name: "+show.getshowname()); system.out.println("show time: "+show.getshowtime()); system.out.println("seats available: "+show.getseatsavailable()); } }
because you've reached end of file.
you seem think readobject() returns null @ end of file. doesn't. returns null if , if wrote null.
the right test grab eofexception , break, not read until readobject() returns null.
java exception eof
Comments
Post a Comment