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 {
}