kryo: com.esotericsoftware.kryo.KryoException: com.esotericsoftware.kryo.K

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流。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值