> ## Documentation Index
> Fetch the complete documentation index at: https://filekit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart Guide

> Get started with FileKit in minutes

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:

<CodeGroup>
  ```kotlin build.gradle.kts theme={null}
  // Enables FileKit dialogs without Compose dependencies
  implementation("io.github.vinceglb:filekit-dialogs:0.15.0")

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

  ```toml libs.versions.toml theme={null}
  [versions]
  filekit = "0.15.0"

  [libraries]
  filekit-dialogs = { module = "io.github.vinceglb:filekit-dialogs", version.ref = "filekit" }
  filekit-dialogs-compose = { module = "io.github.vinceglb:filekit-dialogs-compose", version.ref = "filekit" }
  ```
</CodeGroup>

### File picker

FileKit provides a simple way to open a file picker dialog. Read more about [file picker](/dialogs/file-picker).

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  // 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)
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  // Pick a single file
  val launcher = rememberFilePickerLauncher(
      onError = { failure -> showError(failure.message) },
      onResult = { file ->
          // Handle the selected file, or null when the user cancelled
      },
  )

  Button(onClick = { launcher.launch() }) {
      Text("Pick a file")
  }
  ```
</CodeGroup>

### Directory picker

FileKit makes it easy to open a directory picker dialog. Read more about [directory picker](/dialogs/directory-picker).

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  // Pick a single directory
  val directory = FileKit.openDirectoryPicker()
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  // Pick a single directory
  val launcher = rememberDirectoryPickerLauncher(
      onError = { failure -> showError(failure.message) },
      onResult = { directory ->
          // Handle the selected directory, or null when the user cancelled
      },
  )

  Button(onClick = { launcher.launch() }) {
      Text("Pick a directory")
  }
  ```
</CodeGroup>

### Camera picker

FileKit makes it easy to open a camera picker dialog. Read more about [camera picker](/dialogs/camera-picker).

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  // Pick a single image
  val imageFile = FileKit.openCameraPicker()
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  // Pick a single image
  val launcher = rememberCameraPickerLauncher(
      onError = { failure -> showError(failure.message) },
      onResult = { imageFile ->
          // Handle the selected image, or null when the user dismissed the camera
      },
  )

  Button(onClick = { launcher.launch() }) {
      Text("Pick an image")
  }
  ```
</CodeGroup>

### File saver

FileKit makes it easy to save a file. Read more about [file saver](/dialogs/file-saver).

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  val contentToSave = "Hello FileKit!"

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

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

  ```kotlin filekit-dialogs-compose theme={null}
  // Create a file saver launcher
  val launcher = rememberFileSaverLauncher(
      dialogSettings = FileKitDialogSettings.createDefault(),
      onError = { failure -> showError(failure.message) },
      onResult = { file ->
          // Cancellation is reported as null, not as an error
          file?.let { saveFile(it) }
      },
  )

  // Display a button to open the file saver dialog
  Button(onClick = {
      launcher.launch(
          suggestedName = "document",
          defaultExtension = "txt",
          allowedExtensions = setOf("txt", "md"),
      )
  }) {
      Text("Save a file")
  }

  // Save the file
  val scope = rememberCoroutineScope()
  fun saveFile(file: PlatformFile) = scope.launch {
    val contentToSave = "Hello FileKit!"
    file.writeString(contentToSave)
  }
  ```
</CodeGroup>

### Documentation

<Card icon="window" title="FileKit Dialogs Documentation" href="/dialogs/setup">
  Get started with FileKit Dialogs, installation and usage, here.
</Card>

## Working with files

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

### PlatformFile

[PlatformFile](/core/platform-file) is a Kotlin Multiplatform abstraction for a file with [kotlinx-io](https://github.com/Kotlin/kotlinx-io) interoperability. It facilitates file operations across all platforms.

```kotlin theme={null}
// 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](/core/read-file) documentation.

```kotlin theme={null}
// 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](/core/write-file) documentation.

```kotlin theme={null}
// 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](/core/platform-file#file-operations) documentation.

```kotlin theme={null}
// 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](/core/image-and-video-utils) documentation.

```kotlin theme={null}
// 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,
    imageFormat = ImageFormat.JPEG
)

// Save to device gallery
val saveResult = FileKit.saveImageToGallery(
    filename = "my-photo.jpg",
    bytes = compressedBytes,
)

saveResult.onFailure { error ->
    // Handle save failure
    println("Failed to save image: ${error.message}")
}
```

## File utilities

FileKit provides access to standard platform-specific directories:

```kotlin theme={null}
// 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](/core/file-utils) documentation.

### Documentation

<Card icon="window" title="FileKit Core Documentation" href="/core/setup">
  Get started with FileKit Core, installation and usage, here.
</Card>

## Next Steps

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

* Read the detailed [Core documentation](/core/setup) to learn about platform-specific setup
* Explore [Dialogs documentation](/dialogs/setup) to learn about dialogs

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