readOrNull

open fun readOrNull(path: String, amount: Long = 0, offset: Long = 0, readAll: Boolean = false, mustExist: Boolean = true): ByteArray?

Read bytes from a file at path, returning null if the file does not exist and mustExist is false.

Return

the bytes read from the file, or null if the file does not exist and mustExist is false

Parameters

path

fully qualified path of the file to read

amount

number of bytes to read (ignored when readAll is true)

offset

byte offset to start reading from (ignored when readAll is true)

readAll

if true, reads the entire file contents

mustExist

if true, throws FileNotFoundException when path does not exist; if false, returns null