From c9dd8344d1d18f563fe2a2465669bb4a0952b2d6 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 25 Sep 2019 18:22:15 +0300 Subject: [PATCH] Do not use file length estimate in File.readText This handles the situation when reported file length is less than actual. #KT-33864 --- libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt b/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt index ce3f5190bb5..0d64b9d2cbb 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt @@ -122,7 +122,7 @@ public fun File.appendBytes(array: ByteArray): Unit = FileOutputStream(this, tru * @param charset character set to use. * @return the entire content of this file as a String. */ -public fun File.readText(charset: Charset = Charsets.UTF_8): String = readBytes().toString(charset) +public fun File.readText(charset: Charset = Charsets.UTF_8): String = reader(charset).use { it.readText() } /** * Sets the content of this file as [text] encoded using UTF-8 or specified [charset].