ObjectInputStream 与ObjectOutputStream

 1 import java.io.FileInputStream;
 2 import java.io.FileNotFoundException;
 3 import java.io.FileOutputStream;
 4 import java.io.IOException;
 5 import java.io.ObjectInputStream;
 6 import java.io.ObjectOutputStream;
 7 
 8 import reflect.Student;
 9 
10 public class ObjectInputStreamDemo {
11     public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException{
12         //wrtieObj();
13         readObj();
14     }
15     public static void readObj() throws FileNotFoundException, IOException, ClassNotFoundException{
16         ObjectInputStream ois =
17                 new ObjectInputStream(new FileInputStream("3.txt"));
18         Student s =(Student) ois.readObject();
19         System.out.println(s);
20     }
21     public static void wrtieObj() throws FileNotFoundException, IOException{
22         ObjectOutputStream oos =
23                 new ObjectOutputStream(new FileOutputStream("3.txt"));
24         oos.writeObject(new Student(20,"张三"));
25         
26         oos.close();
27     }
28 
29 }

 

posted @ 2012-06-22 11:35  Carve_Time  阅读(154)  评论(0编辑  收藏  举报