Serialize your own objects in Java

Description

The following code shows how to serialize your own objects.

Example


//from  www  . j  ava  2  s.com
import java.io.FileOutputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
  // Throw exceptions to console:
  public static void main(String[] args) throws Exception {
    ObjectOutput out = new ObjectOutputStream(new FileOutputStream("X.file"));
    MyClass zorcon = new MyClass();
    out.writeObject(zorcon);
  }
}

// A serializable class.
class MyClass implements Serializable {
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip