0
我不知道,我非常理解序列化的概念,我的问题是这样的:每次一个ArrayList添加到序列化的文件
我上课的ArrayList,我称之为历史:
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 = nameOfToCountry;
}
public String getDescription() {
return description;
}
public void setDescription(String description)
{
this.description = description;
}
}
序列化ArrayList中我使用此功能:
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();
}
现在我想,每当我添加一个ArrayList时间序列化不会擦除旧数据,但添加到邻一个新阵列或其他更好的,我成功得到最后一个,
但我不知道我应该做什么来获得所有的arrayList。
感谢您的帮助!
ps:抱歉我的英语!