简体   繁体   English

为什么RandomAccessFile使用int作为偏移量

[英]Why does RandomAccessFile use int as offset

I am writing some data access test implementation and I need random access to file content. 我正在编写一些数据访问测试实现,我需要随机访问文件内容。 Here's the code: 这是代码:

RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rwd");
final byte b[] = IOUtils.toByteArray(source);
randomAccessFile.write(b, (int) offset, size);

where offset has type long. 其中offset的类型为long。 Why doesn't RandomAccessFile provide method: 为什么RandomAccessFile没有提供方法:

public void write(byte b[], long off, int len)

?

How to override this issue? 如何覆盖此问题?

I think you are looking for the seek method. 我想你正在寻找seek方法。

The offset in write is an offset into the array. write中的偏移量是数组的偏移量。 Arrays have int offsets. 数组有int偏移量。 There have been proposals for "long arrays", but were these implemented, you'd still need an overload. 已经提出了“长阵列”的建议,但如果实施了这些建议,你仍然需要过载。

Mapped files in NIO have a problem in that the equivalent MappedByteBuffer.position for some reason only uses int . NIO中的映射文件存在一个问题,即由于某种原因等效的MappedByteBuffer.position只使用int See CR 6347833 (9 votes). CR 6347833 (9票)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM