readBytes() and readString() load the whole file into memory and return a ByteArray or a UTF-8 String. For large files, stream them with source() instead.
Usage
Dispatchers.IO themselves.
Stream a large file
source() returns a kotlinx-io RawSource, so you can process the file in chunks without loading it at once. It is not available on the web.
nonWebMain
source() does blocking I/O: call it on Dispatchers.IO, and close it with use.
Handle errors
FileNotFoundException, other I/O failures throw kotlinx.io.IOException. FileKit’s own errors, such as reading a directory or a content:// Uri that can’t be opened, throw FileKitException.
Platform notes
Related
- Writing files
- PlatformFile: name, size, and other properties