package cn.twelve.File;
/*
*
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
class Student implements Serializable{
String name;
double height;
public Student(String name,double height){
this.name = name;
this.height = height;
}
public void setHeight(double c){
this.height = c;
}
}
public class TestStudent {
public static void main(String[] args) {
Student zhang = new Student("张三",1.65);
try {
FileOutputStream out = new FileOutputStream("C://t.txt");
ObjectOutputStream obj_out = new ObjectOutputStream(out);
obj_out.writeObject(zhang);
FileInputStream in = new FileInputStream("C://t.txt");
ObjectInputStream obj_in = new ObjectInputStream(in);
Student li = (Student) obj_in.readObject();
li.setHeight(1.78);
li.name = "李四";
System.out.println(zhang.name+"身高是"+zhang.height);
System.out.println(li.name+"身高是"+li.height);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}