简体   繁体   中英

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. Why doesn't RandomAccessFile provide method:

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

?

How to override this issue?

I think you are looking for the seek method.

The offset in write is an offset into the array. Arrays have int offsets. 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 . See CR 6347833 (9 votes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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