Android复杂的Serializable对象 - 简单如何

时间:2011-12-31 03:51:45

标签: android serializable

我正在制作自定义Android对象Serializable。应该是简单的我只是找不到一个简单的方法来做到这一点。我得到的事实是我必须重载writeObjectreadObject ...我怎么写和读这个我得不到。初学者......

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?
}
}

1 个答案:

答案 0 :(得分:0)

是什么让你需要覆盖read / writeoObject()?你的班级没有什么特别之处,只需要实施Serializable即可。