[英]RandomAccessFile reading wrong Integers
所以我正在使用RandomAccessFile
将数据写入文件。 由于我正在使用lz4压缩写入的数据,因此首先将未压缩的大小写为整数,然后将压缩后的大小写为整数,最后将其压缩为字节数组。 但是,当读取两个整数时,会出现完全不同的结果。 我写了一个简单的测试,结果如下:
int test = 982364567;
System.out.println("Writing " + test + " in file...");
this.clusterData.seek(1);
this.clusterData.write(test);
this.clusterData.seek(1);
System.out.println("Reading " + this.clusterData.readInt() + " from file...");
clusterData
是RandomAccessFile,控制台中的输出是这样的:
Writing 982364567 in file...
Reading -1761607680 from file...
有人可以向我解释哪里出了问题,而我在这里想念的是什么?
注意, write(int data)
意味着写入由数据表示的byte
。 因此它将写入一个字节。
您需要使用writeInt(int data)
来写入完整整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.