【发布时间】:2012-01-30 22:49:23
【问题描述】:
我正在考虑制作一个自定义 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?
}
}
【问题讨论】:
标签: android serializable