package com.company.bingfa;
import java.io.*;
class Student implements Serializable{
int id;
transient String name;
static int age;
Student(int id, String name){
this.id = id;
this.name = name;
}
@Override
public String toString() {
return id+":"+name+" age:"+age;
}
}
public class MySerializable {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Student st = new Student(1,"James");
Student.age = 10;
FileOutputStream fos = new FileOutputStream("MyStudent.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(st);
oos.close();
fos.close();
FileInputStream fis = new FileInputStream("MyStudent.ser");
ObjectInputStream ois = new ObjectInputStream(fis);
Student st2 = (Student)ois.readObject();
System.out.println(st2);
ois.close();
fis.close();
/*
1:null age:0
*/
}
}