Introduction
FileKit Core provides a consistent API for reading files across all platforms. ThePlatformFile class offers multiple methods to read the contents of a file, from simple byte arrays to more complex streaming operations.
Reading as ByteArray
Supported on Android, iOS, macOS, JVM, JS and WASM targets
readBytes() suspend function, which returns the file contents as a ByteArray:
Reading as String
Supported on Android, iOS, macOS, JVM, JS and WASM targets
readString() suspend function, which returns the file contents as a String:
Using Source
Supported on Android, iOS, macOS, JVM targets
source() method from kotlinx-io to get a raw source:
Error Handling
When reading files, you should handle potential errors:Example: Reading Different File Types
See also: Writing Files for information on how to write to files after reading them.