Reputation: 526
I have this file that I need to read using an allocated buffer:
ByteBuffer buff = ByteBuffer.allocate(n);
But I can't seem to understand how to move data into the buffer before I can print it to console.
I need to do this without using CharBuffer
.
Upvotes: 1
Views: 39
Reputation: 33694
The official way to read from a file into a ByteBuffer
is a FileChannel
:
There are several ways to create FileChannel
objects:
The second method works on Path
types, which can be obtained using java.io.File.getPath()
, or from java.nio.file.FileSystem
.
Upvotes: 1