java - reading an arraylist collection from binary files and assigning each element in new array -


previously, have wrote arraylist data binary file called (itstatebinary.dat)

and trying read arraylist binary file, assign each of element in arraylist array.

so far have this:

public carowner[] readlistfrombinary() throws exception {     string filename = "itstatebinary.dat";     fileinputstream instream = new fileinputstream(filename);     objectinputstream objectinputfile = new objectinputstream(instream);      //need create carowner[] object called temp , return } 

readlistfrombinary() method reads arraylist collection binary file (ltstatebinary.dat). then, each arraylist object item written newly created carowner[] called temp. temp returned calling method.

edit:

 public carowner[] readlistfrombinary() throws exception {     string filename = "itstatebinary.dat";     fileinputstream instream = new fileinputstream(filename);     objectinputstream objectinputfile = new objectinputstream(instream);      arraylist<carowner> read = (arraylist<carowner>)objectinputfile.readobject();      carowner[] temp = read.toarray(new carowner[read.size()]);      return temp; } 

does know whats wrong method? gives me compiler warning

i'm not sure asking, assuming write arraylist file that:

arraylist<carowner> al = new arraylist<carowner>(); fileoutputstream fos = new fileoutputstream("itstatebinary.dat"); objectoutputstream oos = new objectoutputstream(fos); oos.writeobject(al); 

that way, can read way, doing:

fileinputstream fis = new fileinputstream("itstatebinary.dat"); objectinputstream ois = new objectinputstream(fis); arraylist<carowner> read = (arraylist<carowner>)ois.readobject(); 

then return return array arraylist:

return read.toarray(new carowner[read.size()]); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -