Android学习第八天----系列化

java当中的系列化问题
将对象以数据的形式存储到文件中,这个过程叫做系列化。
从文件中加载一个对象,叫做反系列化。
序列化 必须实现serializable接口,
class A implements serializable
{
public int a ;
public A(int x) {this. a = a;}
public void show()
{
System.out.println(a)
}
}
main方法中

系列化
A temp = new A();
FileOutputStream fos = new FileOutputStream("d:\\a.txt");
ObjectOutputStream oos= new ObjectOutputStream(fos);
oos.writeObject(temp)
反系列化
FileInputStream fis = new FileInputStream("d:\\a.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
A temp = (A)oos.readObject();

posted @ 2013-03-13 21:49  小三小山  阅读(168)  评论(0编辑  收藏  举报