Add each time an ArrayList to the serializable file
I am not sure that i understand very well the serializable concept,my question is like that:
I Have an ArrayList of class that i call History:
public class History implements Serializable
{
private static final long serialVersionUID = 1L;
String nameOfMedicaments,DCI,pathologie,nameOfToCountry;
String description;
int DCIN;
public String getNameOfMedicaments() {
return nameOfMedicaments;
}
public void setNameOfMedicaments(String nameOfMedicaments)
{
this.nameOfMedicaments = nameOfMedicaments;
}
public int getDCIN() {
return DCIN;
}
public void setDCIN(int DCIN)
{
this.DCIN = DCIN;
}
public String getDCI() {
return DCI;
}
public void setDCI(String DCI)
{
this.DCI = DCI;
}
public String getPathologie() {
return pathologie;
}
public void setPathologie(String pathologie)
{
this.pathologie = pathologie;
}
public String getNameOfToCountry() {
return nameOfToCountry;
}
public void setNameOfToCountry(String nameOfToCountry)
{
this.nameOfToCountry = nameOfToCoun开发者_如何转开发try;
}
public String getDescription() {
return description;
}
public void setDescription(String description)
{
this.description = description;
}
}
to serialize the arrayList i use this function:
History history=new History();
ArrayList<History> results = new ArrayList<History>();
results.add(history);
FileOutputStream fos;
try {
fos = openFileOutput("history", Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(results);
oos.flush();
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
Now i want that each time that i add an ArrayList to serialize that not going to erase the older data but to add to the older one a new array or whatever its better, i succeed to get the last one ,
but i don't have any idea what i should do to get all the arrayList.
Thanks for Helping!!!
Ps:sorry for my english!!
You can open the file in append mode - see http://developer.android.com/reference/android/content/Context.html#MODE_APPEND
so basically
fos = openFileOutput("history",Context.MODE_APPEND)
and then only write the records that are new
精彩评论