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
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.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
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
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, useFileKit.download. See Files on the web.
Related
- Core setup to set the application ID or custom directories.
- Writing files into these directories.
- Bookmark data to keep access to files outside them.