请教序列化对象的问题!

郭海涛 2003-10-21 04:12:21

   //保存对象状态
public void writeObject(String file)
{

FileOutputStream fo=null;
ObjectOutputStream so=null;
try{
fo=new FileOutputStream(file);
so=new ObjectOutputStream(fo);
so.writeObject(this.toString());
}catch(FileNotFoundException e )
{
System.out.println(e);
}catch(IOException e )
{
System.out.println(e);
}finally
{
try
{
so.close();
}catch(IOException e){}
}
}
//实现
Employee emp= new Employee(name,ID,gender);//设置序列化对象的值
emp.writeObject("employee_obj.ser");

我的问题:
  这样的实现结果每次都删掉了以前保存的序列化对象,我想append序列化对象
怎么改呀?
...全文
44 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
郭海涛 2003-10-21
  • 打赏
  • 举报
回复
谢谢!
TonyTonyQ 2003-10-21
  • 打赏
  • 举报
回复
public FileOutputStream(String name,
boolean append)
throws FileNotFoundException
Creates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧