码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA_ObjectIO

时间:2015-05-11 21:42:07      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

技术分享

 

JAVA_ObjectIO

标签:

原文地址:http://www.cnblogs.com/roger-h/p/4495612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!