Is there an easy and fast way to read two bytes from a 23gb large file in java? The Problem is that read() method (FileInputStream) only supports int as offset. Reading chunks of size 2GB in memory takes to long... There musst be a way to skip let's say 15.000.000.000 bytes?
答案 0 :(得分:6)
Use nio FileChannel position(long newPosition)
method. To get it, call getChannel()
on the good old FileInputStream instance.
答案 1 :(得分:3)
Using FileChannel
and ByteBuffer
:
ByteBuffer bb = ByteBuffer.allocate(1);
FileChannel.open(file.toPath()).position(15e9).read(bb);
byte b = bb.get();