Duplicating method removed from stdlib

This commit is contained in:
Andrey Breslav
2012-11-28 12:40:29 +04:00
parent d487f754cd
commit 9dd167a760
2 changed files with 14 additions and 5 deletions
-5
View File
@@ -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
*
+14
View File
@@ -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<String>()
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()