java - I manage to save, but not to LOAD (Serialization) -


i´m making small game , working serialization. have managed save current state of battleground object, can not seem load it.

this method that´s giving me syntax errors:

//reads battleground object disk. private object readfromfile() {     fileinputstream savefile = new fileinputstream("savegame.obj");     objectinputstream restore = objectinputstream(savefile);     object obj = restore.readobject();     string name = (string) restore.readobject();     restore.close(); } 

i error message "cannot find symbol - method objectinputstream(java.io.fileinputstream). looking method in oracle docs parameter in method supposed of type. have imported whole java.io library. inputs? wrong way it? need method load game. other save-method looks this:

// saves battleground object disk. private void savetofile() {     try{         // serialize data object file         objectoutputstream out = new objectoutputstream(new fileoutputstream("savegame.obj"));         out.writeobject(battleground);         out.close();          // serialize data object byte array         bytearrayoutputstream bos = new bytearrayoutputstream() ;         out = new objectoutputstream(bos) ;         out.writeobject(battleground);         out.close();          // bytes of serialized object         byte[] buf = bos.tobytearray();     } catch (ioexception e) {      } } 

you're missing new keyword

new objectinputstream(savefile) 

i'm wondering why calling readobject() twice

object obj = restore.readobject(); string name = (string) restore.readobject(); 

when savetofile() code writing once

out.writeobject(battleground); out.close(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -