Skip to main content
FileKit.filesDir, FileKit.cacheDir, and FileKit.databasesDir return the app’s private directories as PlatformFiles, mapped to each platform’s conventions. They are declared in nonWebMain, so call them from any source set without JS or Wasm.

Usage

nonWebMain
On JVM, Linux native, and Windows native, call FileKit.init(appId) before reading any of these directories. FileKit.init(appId, filesDir, cacheDir) overrides the locations, and FileKit.init(filesDir, cacheDir) sets both without an app ID. See Core setup.

Directory locations

filesDir and cacheDir always exist when you read them: FileKit creates them on desktop targets if needed. Android and Apple platforms also create databasesDir for you.
On JVM, Linux native, and Windows native, databasesDir is not created automatically. Call FileKit.databasesDir.createDirectories() before writing into it.
On macOS native, cacheDir is the shared user Caches folder, not a per-app subfolder. Add your own subfolder, such as FileKit.cacheDir / "com.example.myapp", when your app isn’t sandboxed.

Use the temporary directory on Apple platforms

FileKit.tempDir returns NSFileManager.temporaryDirectory. It is declared for iOS, macOS, and watchOS only, so call it from an Apple source set such as appleMain or iosMain:
iosMain
The system can delete this directory’s contents when your app is not running.

Get the project directory in tests

FileKit.projectDir exists on every non-web target, but it only makes sense during development and tests: See Test resources to read fixture files with it. Don’t use projectDir in production code.

Open user folders on desktop

On JVM, macOS, Linux native, and Windows native, FileKit resolves the user’s Downloads, Pictures, Videos, Music, and Documents folders:
jvmMain
The shortcuts are downloadsDir, picturesDir, videosDir, musicDir, and documentsDir. They throw a FileKitException when the folder can’t be resolved. These APIs are not declared on Android, iOS, watchOS, or the web. On JVM, Linux native, and Windows native, a missing folder is created when you read it.

Download a file on the web

Browsers have no app directories. To save bytes to the user’s Downloads folder, use FileKit.download. See Files on the web.