标签:
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 }
标签:
原文地址:http://www.cnblogs.com/roger-h/p/4495612.html