我正在制作自定义Android对象Serializable
。应该是简单的我只是找不到一个简单的方法来做到这一点。我得到的事实是我必须重载writeObject
和readObject
...我怎么写和读这个我得不到。初学者......
public class QObject implements Serializable {
public String lq_a;
public String lq_b;
Vector lq_vec;
private void writeObject(java.io.ObjectOutputStream out) throws IOException{
//should I go one by one a output each element?
out.writeBytes(lq_a);
//or is there a simpler way? Like write this object one liner?
out.writeObject(this);
//should I close the ObjectOutputStream?
out.close();
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException{
//baffled here ... how do I read this object?
}
}
答案 0 :(得分:0)
是什么让你需要覆盖read / writeoObject()?你的班级没有什么特别之处,只需要实施Serializable
即可。