Duplicating method removed from stdlib
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user