diff --git a/libraries/stdlib/src/kotlin/io/Files.kt b/libraries/stdlib/src/kotlin/io/Files.kt index 0aa87ee1dae..a53176bdd5d 100644 --- a/libraries/stdlib/src/kotlin/io/Files.kt +++ b/libraries/stdlib/src/kotlin/io/Files.kt @@ -85,11 +85,6 @@ public fun File.relativePath(descendant: File): String { */ public inline fun File.reader(): FileReader = FileReader(this) -/** - * Iterates through each line of this file then closing the underlying [[Reader]] when its completed - */ -public inline fun File.forEachLine(block: (String) -> Any): Unit = reader().forEachLine(block) - /** * Reads the entire content of the file as bytes * diff --git a/libraries/stdlib/test/IoTest.kt b/libraries/stdlib/test/IoTest.kt index b73f1f727af..86d24d32b36 100644 --- a/libraries/stdlib/test/IoTest.kt +++ b/libraries/stdlib/test/IoTest.kt @@ -72,6 +72,20 @@ class IoTest(){ assertEquals(arrayList("Hello", "World"), list) } + test fun testForEachLineFile() { + val file = File.createTempFile("temp", System.nanoTime().toString()) + file.writeText("Hello\nWorld") + + + val list = ArrayList() + file.forEachLine{ + list.add(it) + } + + assertEquals(arrayList("Hello", "World"), list) + file.deleteOnExit() + } + test fun testListFiles() { val dir = File.createTempFile("temp", System.nanoTime().toString()) dir.delete()