Example usage for java.io ObjectOutputStream useProtocolVersion

List of usage examples for java.io ObjectOutputStream useProtocolVersion

Introduction

In this page you can find the example usage for java.io ObjectOutputStream useProtocolVersion.

Prototype

public void useProtocolVersion(int version) throws IOException 

Source Link

Document

Specify stream protocol version to use when writing the stream.

Usage

From source file:Person.java

public static void main(String[] args) throws Exception {
    ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("yourFile.dat"));

    Person person = new Person();
    person.setFirstName("A");
    person.setLastName("B");
    person.setAge(38);/* w  ww .ja  v  a  2  s.c om*/
    outputStream.writeObject(person);

    person = new Person();
    person.setFirstName("C");
    person.setLastName("D");
    person.setAge(22);
    outputStream.writeObject(person);

    outputStream.useProtocolVersion(ObjectStreamConstants.PROTOCOL_VERSION_1);

    outputStream.close();
}