In my java code I want to append massage objects to a file AT THE MOMENT THEY ARE BEING CREATED. When I try to append a new object it overwrites previously added data in the file. Can someone explain a method to append objects (not string type objects) one by one to a existing file without getting overwritten?
Constructor of the object:
public class savedEmail{
String email;
String subject;
String date;
public savedEmail(String email,String subject,String date){
this.email = email;
this.subject = subject;
this.date = date;
}
}
//The way which I tried to append the object to the file:
class sentEmail{
public static void save(saveEmail O) throws IOException{ObjectOutputStream op = new ObjectOutputStream(new
FileOutputStream("saved.bin",true));
op.write(0);
}
}