序列化对象
import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; /* 来自 *时 代 J a v a*/ import java.io.ObjectOutput; import java.io.ObjectOutputStream; public class Main { public void m() { Object object = new javax.swing.JButton("push me"); try { // Serialize to a file ObjectOutput out = new ObjectOutputStream(new FileOutputStream( "filename.ser")); out.writeObject(object); out.close(); /* N o w J a v a . c o m - 时代Java 提 供 */ // Serialize to a byte array ByteArrayOutputStream bos = new ByteArrayOutputStream(); out = new ObjectOutputStream(bos); out.writeObject(object);