JAVA_ObjectIO

时间:2015-05-11 21:42:07   收藏:0   阅读:158

技术分享

 

 1 import java.io.*;
 2 
 3 public class TestObjectIO {
 4     public static void main(String args[]) throws Exception {
 5         T t = new T();
 6         t.k = 8;
 7         FileOutputStream fos = new FileOutputStream("d:/share/java/io/testobjectio.dat");
 8         ObjectOutputStream oos = new ObjectOutputStream(fos);
 9         oos.writeObject(t);
10         oos.flush();
11         oos.close();
12         
13         FileInputStream fis = new FileInputStream("d:/share/java/io/testobjectio.dat");
14         ObjectInputStream ois = new ObjectInputStream(fis);
15         T tReaded = (T)ois.readObject();
16         System.out.println(tReaded.i + " " + tReaded.j + " " + tReaded.d + " " + tReaded.k);
17         
18     }
19 }
20 
21 class T 
22     implements Serializable
23 {
24     int i = 10;
25     int j = 9;
26     double d = 2.3;
27     transient int k = 15;
28 }

 

技术分享

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!