java - Serialization overwrites -


i got problem serialization , deserialization in java. in program whenever create file creating fileinfo object , serializing in secure_store.dat file , after deserializing file also.for example can create test1.txt new fileinfo object , serialize fileinfo object can create test2.txt again different fileinfo object , serialize without problem. whenever deserialize secure_store.dat can see 2 objects problem whenever close program , reopen program , create test3.txt fileinfo object , try serialize, deletes 2 old object in secure_store.dat file , whenever deserialize file can see last object others deleted(which created before program closes). how can solve problem , return 3 objects ? below can see code...

public static void serialization(arraylist<fileinfo> allfiles) {         try {             fileoutputstream fileout = new fileoutputstream("secure_store.dat");             objectoutputstream out = new objectoutputstream(fileout);              out.writeobject(allfiles);             out.close();             fileout.close();          } catch (ioexception i) {             i.printstacktrace();         }     }    @suppresswarnings("unchecked")     public static arraylist<fileinfo> deserialization() throws filenotfoundexception {         arraylist<fileinfo> arraylist = new arraylist<fileinfo>();         try {             fileinputstream filein = new fileinputstream("secure_store.dat");             objectinputstream in = new objectinputstream(filein);             arraylist = (arraylist<fileinfo>) in.readobject();             in.close();             filein.close();          } catch (ioexception i) {             i.printstacktrace();             return arraylist;         } catch (classnotfoundexception c) {             system.out.println("class not found");             c.printstacktrace();             return arraylist;         }         return arraylist;     } 

have how write data fileoutputstream without losing old data?

fileoutputstream fileout = new fileoutputstream(new file("secure_store.dat"),true); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -