ObjectOutputStream in Java

The Object stream is a mixture of primitive data type and object values. The ObjectOutputStream class is a lot like DataOutputStream class, except that it includes the powerful writeObject() method. The ObjectInputStream class implements ObjectOutput class which is sub interface of DataOutput class.  

Example:

/**
From objectOutputStream.java
*/

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.Hashtable;

/**
 *
 * @author JavaHotSpot
 */

public class objectOutputStream
{
    public static void main(String args[])
    {
  try
      {
          Hashtable ht = new Hashtable();
          ht.put("Name","ABC");
          ht.put("Roll", new Integer(12));
          ht.put("Percentage", new Double(98.56));

          FileOutputStream fs = new FileOutputStream("C:\\file2.txt");
          ObjectOutputStream obj = new ObjectOutputStream(fs);
          obj.writeObject(ht);
          obj.close();

          System.out.append("Done...!");


      }
      catch(Exception ex)
      {
          System.err.println(ex);
      }
    }
}

Output: