I have a gigantic 2GB text file which I want to read line by line without pushing everything to memory. I have written the following code snippet for that but it doesn't seem to work at yield
call. How should I return the line iterator from a function then?
import java.io.{BufferedReader, File, FileInputStream, InputStream, InputStreamReader}
import java.nio.charset.StandardCharsets
def readLines(fileName: String): Iterable[String] = {
val bufferedReader = new BufferedReader(new InputStreamReader(getClass.getClassLoader.getResourceAsStream(fileName), StandardCharsets.UTF_8))
for (line <- bufferedReader.readLine()) {
yield line
}
}