Mika'il Mika'il - 1 year ago 96
Scala Question

No output when reading file

I'm using Akka FileIO to read a file line by line as follows:

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem("MySys")
implicit val materializer = ActorMaterializer()
FileIO.fromPath(Paths.get("/foo/1.csv")).via(Framing.delimiter(ByteString("\n"), 256, true).map(_.utf8String)).runForeach(println)

But when I run this, I see no output on the console. The file path is correct and there are contents in the file. What am I doing wrong?

Answer Source

You terminate AkkaSystem before it has opportunity to process your file.

Do something like this

  .via {
    Framing.delimiter(ByteString("\n"), 256, true).map(_.utf8String)
  .onComplete{ _ =>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download