klyn.io.Files.readBytesInto
method
public static readBytesInto(path as String, notnull buffer as Byte[], offset as Long = 0l, length as Long = -1l) as Long
Description

Reads bytes from a file directly into an existing byte buffer without allocating a stream object or an intermediate byte array.

Parameters
ParameterDescription
pathSource file path.
bufferDestination byte buffer to fill.
offsetNon-negative file byte offset where reading begins.
lengthMaximum number of bytes to read; -1 reads up to buffer.size.
Returns

Number of bytes actually read (0 at or past end-of-file).

Throws
  • IOException if the path is empty, cannot be opened, or reading fails.
  • IndexException if offset is negative or length exceeds buffer.size.
Example
import klyn.io

scratch as Byte[] = Byte[4096]
count = Files.readBytesInto("README.md", scratch)
print(count)