ObjectOutputStream class

                                       
    java.lang.Object                                  
     |                                 
     |--java.io.OutputStream                              
         |                             
         |--java.io.ObjectOutputStream                          
                                       

An ObjectOutputStream writes primitive data types and Java objects to an OutputStream.

ConstructorSummary
ObjectOutputStream(OutputStream out)Creates an ObjectOutputStream that writes to the specified OutputStream.

ReturnMethodSummary
voidclose()Closes the stream.
voiddefaultWriteObject()Write the non-static and non-transient fields of the current class to this stream.
voidflush()Flushes the stream.
voidreset()Reset will disregard the state of any objects already written to the stream.
voiduseProtocolVersion(int version)Specify stream protocol version to use when writing the stream.
voidwrite(byte[] buf)Writes an array of bytes.
voidwrite(byte[] buf, int off, int len)Writes a sub array of bytes.
voidwrite(int val)Writes a byte.
voidwriteBoolean(boolean val)Writes a boolean.
voidwriteByte(int val)Writes an 8 bit byte.
voidwriteBytes(String str)Writes a String as a sequence of bytes.
voidwriteChar(int val)Writes a 16 bit char.
voidwriteChars(String str)Writes a String as a sequence of chars.
voidwriteDouble(double val)Writes a 64 bit double.
voidwriteFields()Write the buffered fields to the stream.
voidwriteFloat(float val)Writes a 32 bit float.
voidwriteInt(int val)Writes a 32 bit int.
voidwriteLong(long val)Writes a 64 bit long.
voidwriteObject(Object obj)Write the specified object to the ObjectOutputStream.
voidwriteShort(int val)Writes a 16 bit short.
voidwriteUnshared(Object obj)Writes an "unshared" object to the ObjectOutputStream.
voidwriteUTF(String str)Primitive data write of this String in modified UTF-8 format.
Revised from Open JDK source code

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

public class Main {
  public static void main(String args[]) throws IOException {
    FileOutputStream fos = new FileOutputStream("t.tmp");
    ObjectOutputStream oos = new ObjectOutputStream(fos);

    oos.writeInt(12345);
    oos.writeObject("Today");
    oos.writeObject(new Date());

    oos.close();

  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.