java - Issue with Deserialization -


i have method in program reads file, , have associated both fileinputstream variable , objectinputstream variable. however, not know how many objects serialized in file when run program, not know how many objects deserialize using method readobject(). method project:

public void importresults(file file) throws filenotfoundexception, ioexception, classnotfoundexception {     testentry entry = null;     try(fileinputstream fis = new fileinputstream(file)) {         objectinputstream ois = new objectinputstream(fis);          tests.clear();          entry = (testentry)ois.readobject();          tests.add(entry);          ois.close();     } } 

the variable entry store testentry objects deserialize file. problem is, if try deserialize many objects, eofexception. how program figure out how many objects there serialized in file can deserialized right amount? appreciated! thank you.

just read in loop until eofexception, thrown when there no more objects read.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -