FileDocCategorySizeDatePackage
SerialDemo.javaAPI DocExample1183Tue Aug 22 21:14:26 BST 2000None

SerialDemo

public class SerialDemo extends Object implements Serializable
Example 6-2.

Fields Summary
int
test_val
Constructors Summary
public SerialDemo()

 // value defaults to 7

      
        super();
    
public SerialDemo(int x)

        super();
        test_val = x;
    
Methods Summary
public intgetVal()

        return test_val;
    
public static voidmain(java.lang.String[] args)

        try {
            { // Save a SerialDemo object with a value of 5.
                FileOutputStream f = new FileOutputStream("/tmp/testing");
                ObjectOutputStream s = new ObjectOutputStream(f);
                SerialDemo d= new SerialDemo(5);

                s.writeObject(d);
                s.flush();
            }
            { // Now restore it and look at the value.
                FileInputStream f = new FileInputStream("/tmp/testing");
                ObjectInputStream s = new ObjectInputStream(f);
                SerialDemo d = (SerialDemo)s.readObject();

                System.out.println("SerialDemo.getVal() is: " +
                                   d.getVal());
            }
        }
        catch( Exception e ) {
            e.printStackTrace();
        }