子类
ObjectOutputStream并覆盖
writeStreamHeader方法:
public class AppendingObjectOutputStream extends ObjectOutputStream { public AppendingObjectOutputStream(OutputStream out) throws IOException { super(out); } @Override protected void writeStreamHeader() throws IOException { // do not write a header, but reset: // this line added after another question // showed a problem with the original reset(); }}要使用它,只需检查历史文件是否存在,然后实例化此可附加流(如果文件存在=如果我们追加=我们不需要头)或原始流(如果文件不存在=实例化)我们需要一个标头)。



