Skip to main content

How to iterate over the lines of an InputStream in Scala

import java.io.{BufferedReader, InputStream, InputStreamReader}

val is = new InputStream()

val bufferedReader = new BufferedReader(new InputStreamReader(is))

Iterator
  .continually(bufferedReader.readLine())
  .takeWhile { _ != null }
  .foreach { line => println(line) }