FileDocCategorySizeDatePackage
Serial1.javaAPI DocExample1371Sat Sep 12 03:01:00 BST 1998None

Serial1

public class Serial1 extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    write();
    read();
    
public static voidread()

    try
      {
      // read map from file
      ObjectInputStream s = new ObjectInputStream( new FileInputStream( "Serial1.ser" ) );
      HashMap map = (HashMap)s.readObject();
      System.out.println( "ORB means " + map.get( "ORB" ) );
      System.out.println( "FAQ means " + map.get( "FAQ" ) );
      }
    catch ( IOException e1 )
      {
      System.out.println( "caught: " + e1 );
      }
    catch ( ClassNotFoundException e2 )
      {
      System.out.println( "caught: " + e2 );
      }
    
public static voidwrite()

    try
      {
      // create a map of acronyms
      HashMap map = new HashMap();
      map.add( "FAQ", "Frequently Asked Questions" );
      map.add( "OMG", "Object Management Group" );
      map.add( "ORB", "Object Request Broker" );

      // save map to a file
      ObjectOutput s =  new ObjectOutputStream( new FileOutputStream( "Serial1.ser" ) );
      s.writeObject( map );
      s.flush();
      s.close();
      }
    catch ( IOException e )
      {
      System.out.println( "caught: " + e );
      }