From e542521ece38ad9a6af5c43ceca870f4590db14e Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Mon, 28 Oct 2024 19:55:40 +0100 Subject: [PATCH] Make sure to always truncate the file when writing (#200) The append action fully rewrites the file, so we should open in truncate mode in this case as well. Fixes #197. --- app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt b/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt index c1168ae..c9d688f 100644 --- a/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt +++ b/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt @@ -142,7 +142,7 @@ class LedgerRepository if (!matches(fileUri)) { onMismatch() } else { - context.contentResolver.openOutputStream(fileUri, "w") + context.contentResolver.openOutputStream(fileUri, "wt") ?.let { OutputStreamWriter(it) } ?.use { fileContents.value!!.forEach { line ->