In fact, akka-streams provides a direct read function from a file.
FileIO.fromPath(Paths.get("a.csv")) .via(Framing.delimiter(ByteString("\n"), 256, true).map(_.utf8String)) .runForeach(println)
Here, the runForeach method is for printing lines. If you have the correct Sink to handle these strings, use it instead of this function. For example, if you want to split the lines by ' and print the total number of words in it:
val sink: Sink[String] = Sink.foreach(x => println(x.split(",").size)) FileIO.fromPath(Paths.get("a.csv")) .via(Framing.delimiter(ByteString("\n"), 256, true).map(_.utf8String)) .to(sink) .run()
source share