DataInput.readInt()报错:java.io.EOFException

实现WritableComparable接口序列化时,在readFields方法里,使用DataInput的readInt方法读取在write方法里写的int,报错:EOFException。
这个错的意思是:输入流已经到了结尾,在这里的意思就是说,输入流里不够一个整形(32位),查到的问题是:在write方法里,没有使用writeInt而使用了write方法。虽然这个错误很低级,我们都知道readInt要和writeInt配套使用,还是好奇查了一下write这个方法。这个方法的官方解释是:Writes to the output stream the eight low-order bits of the argument .(将参数的八个低位写入输出流。)所以,问题就很明显了,只写了低八位,当然不够读了。修改为writeInt即可。

你可能感兴趣的:(java)