这是我用于读取平面缓冲区文件的代码。我总是得到一个 EOF 异常。我如何摆脱那个异常......
File file = new File("/Users/samarnath/RmsOne/CreateFlatBuffer/src/com/rms/objects/SingleCoverRiskPolicy.fb");
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
int size;
byte[] data = new byte[0];
while ((randomAccessFile.read(data, 0, 0)) != -1)
{
try {
size = randomAccessFile.readInt();
data = new byte[size];
randomAccessFile.read(data, 0, size);
ByteBuffer bb = ByteBuffer.wrap(data);
SingleCoverRiskPolicy singleCoverRiskPolicy = SingleCoverRiskPolicy.getRootAsSingleCoverRiskPolicy(bb);
System.out.println(singleCoverRiskPolicy.id());
} catch (EOFException e) {
randomAccessFile.close();
e.printStackTrace();
}
}