public synchronized long writeObject(Serializable obj) throws IOException
{
ByteArrayOutputStream bao = new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(bao);//将读入的对象放入bao中
oos.writeObject(obj);
oos.flush();
int datalength=bao.size();
long datapos=datafile.length();
datafile.seek(datapos);
datafile.writeInt(datalength);
datafile.write(bao.toByteArray());
return datapos; }
要写入的对象必须实现Serializable接口
{
ByteArrayOutputStream bao = new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(bao);//将读入的对象放入bao中
oos.writeObject(obj);
oos.flush();
int datalength=bao.size();
long datapos=datafile.length();
datafile.seek(datapos);
datafile.writeInt(datalength);
datafile.write(bao.toByteArray());
return datapos; }
要写入的对象必须实现Serializable接口
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货