diff --git a/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt b/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt index 6e68c1e1..816988fa 100644 --- a/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt +++ b/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt @@ -49,6 +49,9 @@ class DirsServiceAndroid( val downloadsDir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) val file = downloadsDir.resolve(fileName) + // Ensure the parent directory does exist + // before writing the file. + file.parentFile?.mkdirs() file.outputStream() .use { write(it) diff --git a/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt b/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt index 14682300..297f9f46 100644 --- a/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt +++ b/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt @@ -47,6 +47,9 @@ class DataDirectory( .bind() .let(::File) val file = downloadsDir.resolve(fileName) + // Ensure the parent directory does exist + // before writing the file. + file.parentFile?.mkdirs() file.outputStream() .use { write(it)