Both File.bufferedWriter and File.printWriter actually rewrite the target file, replacing its content with what you write with them. This is mostly equivalent to what would happen if you used f.writeText(...), not f.appendText(...).

One solution would be to create a FileOutputStream in the append mode by using the appropriate constructor FileOutputStream(file: File, append: Boolean), for example:

FileOutputStream(f, true).bufferedWriter().use { writer ->
    //... 
}
Answer from hotkey on Stack Overflow
🌐
TutorialKart
tutorialkart.com › kotlin › append-text-to-file-in-kotlin
How to append text to file in Kotlin?
March 22, 2023 - To append text to a file in Kotlin, we can use File.appendText() method.
🌐
Programiz
programiz.com › kotlin-programming › examples › append-text-existing-file
Kotlin Program to Append Text to an Existing File
Likewise, the text to be added is stored in the variable text. Then, inside a try-catch block we use Files' write() method to append text to the existing file.
🌐
Baeldung
baeldung.com › home › kotlin › kotlin io › writing to a file in kotlin
Writing to a File in Kotlin | Baeldung on Kotlin
April 28, 2026 - No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with. In this quick tutorial, we’ll learn about various ways of writing content into a file using Kotlin extension methods – available in its standard library.
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
Appending to a text file with FileWriter & bufferedWriter - Support - Kotlin Discussions
March 16, 2022 - Hi All, In the following example using FileWriter, two lines are appended to a text file using both the .write() and .append() methods, when the context mode is set to APPEND (true)… File("test_file2.txt").bufferedWriter().use { out-> out.write(("Line 1\r\n")) out.write(("Line 2\r\n")) } FileWriter( "test_file2.txt", true ).use { out -> out.write("Appended Line 3\r\n") // append works here out.append("Appended Line 4\r\n") // append works here too!
🌐
CodeSignal
codesignal.com › learn › courses › fundamentals-of-text-data-manipulation-in-kotlin › lessons › writing-to-files-in-kotlin
Writing to Files in Kotlin | CodeSignal Learn
Sometimes, you may want to add data to an existing file without overwriting its current contents. This can be easily achieved in Kotlin using the Files.write method with the StandardOpenOption.APPEND flag.
🌐
Medium
cdpateldigitalroom.medium.com › files-in-android-read-write-append-data-using-kotlin-7a6b2d70de1c
📂 Files in Android: Read, Write & Append Data using Kotlin 📖 | by Sarthak Education (CDPatel Digital Room) | Medium
April 26, 2025 - val content = readFromFile(this, "notes.txt") Log.d("FileExample", "File content: $content") ✅ You can show this content in a TextView or Toast! Sometimes, we don’t want to erase old data — we just want to add more text to the end 📌 · fun appendToFile(context: Context, fileName: String, data: String) { try { context.openFileOutput(fileName, Context.MODE_APPEND).use { it.write(("\n$data").toByteArray()) } Log.d("FileExample", "Data appended successfully!") } catch (e: Exception) { e.printStackTrace() } }
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.io › append-text.html
appendText | Core API – Kotlin Programming Language
kotlin-stdlib/kotlin.io/appendText · JVM · fun File.appendText(text: String, charset: Charset = Charsets.UTF_8)(source) Appends text to the content of this file using UTF-8 or the specified charset.
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.io › java.io.-file › append-text.html
appendText - Kotlin Programming Language
June 17, 2022 - Try the revamped Kotlin docs design! ... Appends text to the content of this file using UTF-8 or the specified charset.
Find elsewhere
🌐
Techie Delight
techiedelight.com › home › java › add text to end of a file in kotlin
Add text to end of a file in Kotlin | Techie Delight
2 weeks ago - There are numerous methods to add text at the end of a file in Kotlin: A simple and fairly efficient solution to call the Files.write() function to write text to a file with append mode since the default behavior of this function is to overwrite ...
🌐
Beecoder
beecoder.org › english › kotlin › append text to an existing file
Append Text to an Existing File, Kotlin | 🐝 / Coder
July 23, 2025 - Append Text to an Existing File, code examples and answer to questions in Kotlin programming luaguage | 🐝 beecoder.org
🌐
Chercher
chercher.tech › null › null › read and write files in kotlin
Read and write files in Kotlin
August 29, 2018 - In the case of writing to a file, ... the file. You can append text into an existing file in Kotlin by opening a file using appendText() function in File class....
🌐
Stack Overflow
stackoverflow.com › questions › 69001349 › how-to-append-data-in-a-file-in-android
kotlin - How to append data in a file in Android? - Stack Overflow
try { val collection = MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) val dirDest = File(Environment.DIRECTORY_DOCUMENTS, context.getString(R.string.app_name)) // subfolder with name of the App //val date = System.currentTimeMillis() // current datetime val contentValues = ContentValues().apply { put(MediaStore.MediaColumns.DISPLAY_NAME, fileName) //put(MediaStore.MediaColumns.MIME_TYPE, "application/txt") //put(MediaStore.MediaColumns.DATE_ADDED, date) //put(MediaStore.MediaColumns.DATE_MODIFIED, date) put(MediaStore.MediaColumns.RELATIVE_PATH, "$dirDest${File.separator}")
🌐
DhiWise
dhiwise.com › post › how-to-use-kotlin-write-to-file-practical-methods
Kotlin Write to File: A Complete Guide For File Handling
January 21, 2025 - Kotlin simplifies file handling by leveraging its expressive syntax and Java compatibility. Writing to files involves saving text to a txt file, appending data, or working with structured formats.
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
Appending to a text file with FileWriter & bufferedWriter - #5 by Slouch - Support - Kotlin Discussions
March 17, 2022 - Hi All, In the following example using FileWriter, two lines are appended to a text file using both the .write() and .append() methods, when the context mode is set to APPEND (true)… File("test_file2.txt").bufferedWri…
🌐
Sling Academy
slingacademy.com › article › appending-data-to-existing-files-in-kotlin
Appending Data to Existing Files in Kotlin - Sling Academy
You can use IntelliJ IDEA, which has excellent support for Kotlin, or any other IDE of your choice that supports Kotlin. To append data to an existing file in Kotlin, you can use the java.io.File class directly and its extension functions.
🌐
BezKoder
bezkoder.com › home › ways to write to file in kotlin
Ways to write to File in Kotlin - BezKoder
January 24, 2024 - This tutorial shows you ways to write to File in Kotlin using PrintWriter, BufferedWriter or Kotlin extension functions such as writeText() or write(). You’ll also know how to write Kotlin objects/JSON to a file. Related Posts: – How to read File in Kotlin – Kotlin – Convert object to/from JSON string using Gson Overview Here […]
🌐
Android Developers
developer.android.com › api reference › filewriter
FileWriter | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体