public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
letterstates = (String)in.readObject();
num = in.read(); //把数字88加进来
}
public void putOut(){ //测试
System.out.println(letterstates +num);
}
}
序列化上面的Test类:AppTest
import java.io.*;
public class AppTest {
private void saveGame(){
Test m = new Test();
if (m != null){
try{
FileOutputStream ostream = new FileOutputStream("t.txt");
ObjectOutputStream p = new ObjectOutputStream(ostream);
p.writeObject(m); //writeExternal()自动执行
p.flush();
ostream.close();
} catch (IOException ioe) {
System.out.println ("Error saving file:");
System.out.println (ioe.getMessage());
}
}
}