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.

File Dialogs

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 dependencies
implementation("io.github.vinceglb:filekit-dialogs:0.10.0-beta01")

// Enables FileKit dialogs with Composable utilities
implementation("io.github.vinceglb:filekit-dialogs-compose:0.10.0-beta01")

File picker

FileKit provides a simple way to open a file picker dialog. Read more about file picker.

// Pick a single file
val file = FileKit.openFilePicker()

// Pick multiple files
val files = FileKit.openFilePicker(mode = FileKitMode.Multiple())

// Pick only image files
val imageFile = FileKit.openFilePicker(type = FileKitType.Image)

Directory picker

FileKit makes it easy to open a directory picker dialog. Read more about directory picker.

// Pick a single directory
val directory = FileKit.openDirectoryPicker()

Camera picker

FileKit makes it easy to open a camera picker dialog. Read more about camera picker.

// Pick a single image
val imageFile = FileKit.openCameraPicker()

File saver

FileKit makes it easy to save a file. Read more about file saver.

val contentToSave = "Hello FileKit!"

// Open save dialog to let user choose location
val file = FileKit.openFileSaver(suggestedName = "document", extension = "txt")

// Write content to the file
file?.writeString(contentToSave)

Documentation

FileKit Dialogs Documentation

Get started with FileKit Dialogs, installation and usage, here.

Working with files

FileKit helps you work with files on your Kotlin Multiplatform project.

PlatformFile

PlatformFile is a Kotlin Multiplatform abstraction for a file with kotlinx-io interoperability. It facilitates file operations across all platforms.

// Pick a file
val file = FileKit.openFilePicker()

// Get a file reference
val file = FileKit.filesDir / "document.pdf"

// Get the file properties
val name: String = file.name
val extension: String = file.extension
val path: String = file.path
val size: Long = file.size()
val absolutePath: String = file.absolutePath()
val parent: PlatformFile? = file.parent()
val exists: Boolean = file.exists()
val isFile: Boolean = file.isRegularFile()
val isDirectory: Boolean = file.isDirectory()

// And more...

Reading Files

For more details, see the Reading Files documentation.

// Read as bytes
val bytes: ByteArray = file.readBytes()

// Read as text
val text: String = file.readString()

// Read large files with streaming API
file.source().buffered().use { source ->
    // Process chunks of data
}

Writing Files

For more details, see the Writing Files documentation.

// Write text to a file
file.writeString("Hello, FileKit!")

// Write binary data
val data: ByteArray = getImageData()
file.write(data)

// Write with streaming API for large files
file.sink(append = false).buffered().use { sink ->
    sink.writeString("First line\n")
    sink.writeString("Second line\n")
    // Write more data as needed
}

File operations

For more details, see the File operations documentation.

// Create directories
file.createDirectories()

// Copy file
file.copyTo(destinationFile)

// Move file
file.atomicMove(destinationFile)

// Delete file
file.delete()

Image utilities

FileKit provides utilities for image compression and saving to the gallery. Read more about image utilities documentation.

// Compress an image
val originalImage = PlatformFile("/path/to/photo.jpg")
val compressedBytes = FileKit.compressImage(
    bytes = originalImage.readBytes(),
    quality = 80,  // 0-100
    maxWidth = 1024,
    maxHeight = 1024,
    compressFormat = CompressFormat.JPEG
)

// Save to device gallery
FileKit.saveImageToGallery(
    fileName = "My Photo",
    bytes = compressedBytes,
    format = CompressFormat.JPEG
)

File utilities

FileKit provides access to standard platform-specific directories:

// Get the application's files directory
val filesDir: PlatformFile = FileKit.filesDir

// Get the application's cache directory
val cacheDir: PlatformFile = FileKit.cacheDir

// Get the application's databases directory
val databasesDir: PlatformFile = FileKit.databasesDir

Read more about File utilities documentation.

Documentation

FileKit Core Documentation

Get started with FileKit Core, installation and usage, here.

Next Steps

Now that you’ve seen the basics of FileKit, you can:

FileKit makes file operations simple and consistent across all platforms. Start building your cross-platform app with a powerful file system abstraction today!