January 2018
Intermediate to advanced
434 pages
14h 1m
English
BufferedReader provides us with a lot of methods that we can use to read contents of the file or input stream line by line. Using useLines(), we get a sequence of lines that we can then iterate on using forEach. A user may terminate the iteration loop, so the caller needs to close the BufferedReader, which is what useLines() does. We can only iterate over the sequence returned once.
The syntax for useLines() is this:
inline fun <T> File.useLines( charset: Charset = Charsets.UTF_8, block: (Sequence<String>) -> T): T
Read now
Unlock full access