January 2018
Intermediate to advanced
434 pages
14h 1m
English
In the given steps, we will learn how to use BufferedReader to read a file line by line:
import java.io.Fileimport java.io.InputStreamfun main(args: Array<String>) { val listOfLines = mutableListOf<String>() val inputStream: InputStream = File("lorem.txt").inputStream() inputStream.bufferedReader().useLines { lines -> lines.forEach { var x = "# (" + it.length + ") " + it.substring(0,8); listOfLines.add(x) } } listOfLines.forEach{println(it)}}
The output, in this case, is as follows:
# (56) Lorem ip# (65) Nunc con# (64) Proin he# (84) Proin ut# (47) Sed tinc# (81) Integer# (71) Curabitu# (24) ...
Read now
Unlock full access