File utilities
Utility functions for working with files in Kotlin Multiplatform
Standard Directories
FileKit provides access to standard platform-specific directories:
These directories are automatically created if they don’t exist and are properly sandboxed on each platform.
Platform-specific Directory Behavior
Each platform maps these standard directories to different locations according to platform conventions:
Android
- filesDir: Maps to
context.filesDir
, which is the app’s private internal storage - cacheDir: Maps to
context.cacheDir
, which is the app’s private cache directory - databasesDir: Maps to a
databases
subdirectory in the app’s internal storage
iOS
- filesDir: Maps to the app’s Documents directory, which is backed up with iCloud
- cacheDir: Maps to the app’s Caches directory, which isn’t backed up and may be cleared by the system
- databasesDir: Maps to a
databases
subdirectory in the app’s Documents directory
macOS
- filesDir: Maps to
~/Library/Application Support/<app-id>/
, requiring FileKit initialization with an app ID - cacheDir: Maps to
~/Library/Caches/<app-id>/
- databasesDir: Maps to a
databases
subdirectory in the application support directory
JVM (Desktop)
- filesDir: Maps to platform-specific app data locations:
- Linux:
~/.local/share/<app-id>/
- macOS:
~/Library/Application Support/<app-id>/
- Windows:
%APPDATA%/<app-id>/
- Linux:
- cacheDir: Maps to platform-specific cache locations:
- Linux:
~/.cache/<app-id>/
- macOS:
~/Library/Caches/<app-id>/
- Windows:
%LOCALAPPDATA%/<app-id>/Cache/
- Linux:
- databasesDir: Maps to a
databases
subdirectory within filesDir
On JVM and macOS platforms, you must initialize FileKit with an application ID before accessing these directories. See the Setup guide for details.
Additional Directories
On some platforms, FileKit provides additional standard directories:
Directory Usage Example
Downloading files from web
FileKit provides a convenient way to download files in web environments (JS and WASM targets). This functionality allows users to save files from your web application to their local device: