Exception in thread "main" com.esotericsoftware.kryo.KryoException: com.esotericsoftware.kryo.KryoException: Buffer underflow.
Serialization trace:
age (int)
at com.esotericsoftware.kryo.serializers.ReflectField$IntReflectField.read(ReflectField.java:199)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:129)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:777)
at Test.readObject(Test.java:20)
at Test.main(Test.java:14)
Caused by: com.esotericsoftware.kryo.KryoException: Buffer underflow.
at com.esotericsoftware.kryo.io.Input.require(Input.java:219)
at com.esotericsoftware.kryo.io.Input.readVarInt(Input.java:407)
at com.esotericsoftware.kryo.serializers.ReflectField$IntReflectField.read(ReflectField.java:195)
... 4 more
修改前:
public static void writeObject(String path, Kryo kryo) throws FileNotFoundException {
Person person = new Person("zhangsan", 20, 18, 3);
Output output = new Output(new FileOutputStream(path));
kryo.writeObject(output, person);
}
修改后:
public static void writeObject(String path, Kryo kryo) throws FileNotFoundException {
Person person = new Person("zhangsan", 20, 18, 3);
Output output = new Output(new FileOutputStream(path));
kryo.writeObject(output, person);
output.close();
}
写入后需要关闭Output流。