[douban] 02_对象序列化Serializable和Parcelable

Android 4.0

对象序列化Serializable和Parcelable 
序列化,持久化,对象序列化,对象持久化

让对象实现 implements  Serializable 接口把对象存放到文件上. 
①序列化到文件,写入
让类实现Serializable 接口,然后可以通过 ObjectOutputStream          //对象输出流 
        File file = new File("c:\\1.obj");
        FileOutputStream fos  = new FileOutputStream(file);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
 
        Student stu = new Student();
        stu.setId("10001");
        stu.setName("zs");
        oos.writeObject(stu);
 
 ②反序列化,读取
        FileInputStream fis = new FileInputStream(file);
        ObjectInputStream ois = new ObjectInputStream(fis);
         Student stu1 = (Student) ois.readObject();
        System.out.println(stu1.getName());

Parcelable 和 Serializable
 
Parcelable 把对象序列化到android操作系统 的一块公用的内存空间 
Parcelable比  Serializable效率要高一些