Yurttas/PL/OOL/Java/F/06/03/01/Serialization01.java

 1/**
 2 *  Copyright(C) 1998
 3 *  All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4 *
 5 *  Permission to use, copy, modify, and distribute this
 6 *  software and its documentation for EDUCATIONAL purposes
 7 *  and without fee is hereby granted provided that this
 8 *  copyright notice appears in all copies.
 9 *
10 *  @date   : January 1, 1998.
11 *  @authorĀ : Salih Yurttas.
12 */
13
14
15import java.io.*;
16
17public class Serialization01 {
18  public static void main(String[] args)
19    throws IOException
20  {
21    try {
22      FileOutputStream fOS = new FileOutputStream("DataA.sod");
23      ObjectOutput oO = new ObjectOutputStream(fOS);
24
25      oO.writeObject(new DataA());
26      oO.flush();
27      oO.close();
28
29      fOS = new FileOutputStream("DataB.sod");
30
31      oO = new ObjectOutputStream(fOS);
32      oO.writeObject(new DataB());
33      oO.flush();
34      oO.close();
35
36      FileInputStream fIS = new FileInputStream("DataA.sod");
37
38      ObjectInputStream oIS = new ObjectInputStream(fIS);
39      DataA dA = (DataA)oIS.readObject();
40      oIS.close();
41
42      fIS = new FileInputStream("DataB.sod");
43      oIS = new ObjectInputStream(fIS);
44      DataB dB = (DataB) oIS.readObject();
45      oIS.close();
46      System.out.println("DataB.a " + dB.a);
47    }
48    catch(IOException iOE) {
49      iOE.printStackTrace();
50    }
51    catch(ClassNotFoundException cNFE) {
52      cNFE.printStackTrace();
53    }
54  }
55
56}