FileKit is a powerful Kotlin Multiplatform library for cross-platform file operations. This guide will quickly get you up and running with FileKit, demonstrating its key features.
FileKit can helps you to display dialogs to the user like file, directory and photo pickers, save dialogs, camera and more. FileKit dialogs are available in two flavors:
// Enables FileKit dialogs without Compose dependenciesimplementation("io.github.vinceglb:filekit-dialogs:0.10.0-beta04")// Enables FileKit dialogs with Composable utilitiesimplementation("io.github.vinceglb:filekit-dialogs-compose:0.10.0-beta04")
FileKit makes it easy to save a file. Read more about file saver.
val contentToSave = "Hello FileKit!"// Open save dialog to let user choose locationval file = FileKit.openFileSaver(suggestedName = "document", extension = "txt")// Write content to the filefile?.writeString(contentToSave)
For more details, see the Reading Files documentation.
// Read as bytesval bytes: ByteArray = file.readBytes()// Read as textval text: String = file.readString()// Read large files with streaming APIfile.source().buffered().use { source -> // Process chunks of data}
For more details, see the Writing Files documentation.
// Write text to a filefile.writeString("Hello, FileKit!")// Write binary dataval data: ByteArray = getImageData()file.write(data)// Write with streaming API for large filesfile.sink(append = false).buffered().use { sink -> sink.writeString("First line\n") sink.writeString("Second line\n") // Write more data as needed}
FileKit provides access to standard platform-specific directories:
// Get the application's files directoryval filesDir: PlatformFile = FileKit.filesDir// Get the application's cache directoryval cacheDir: PlatformFile = FileKit.cacheDir// Get the application's databases directoryval databasesDir: PlatformFile = FileKit.databasesDir
FileKit makes file operations simple and consistent across all platforms. Start building your cross-platform app with a powerful file system abstraction today!