In this recipe, we are going to retrieve the contents of a file as a set of consecutive text lines. We are going to use the standard library extension function, File.readLines(), to return a List of a String type representing the next lines of the given File instance.
Reading the contents of a file line by line
Getting ready
Make sure you have a sample non-empty file included in your project to read its contents. You can clone the sample project provided with the book at the GitHub repository: https://github.com/PacktPublishing/Kotlin-Standard-Library-Cookbook. In this recipe, we are going to use the file1.txt file located in the src/main/resources directory in the sample project.