0
votes

I'm coding a small Akka Streams sample where I want to write elements of a List to a local TXT file

implicit val ec = context.dispatcher
implicit val actorSystem = context.system
implicit val materializer = ActorMaterializer()

val source = Source(List("a", "b", "c"))
  .map(char => ByteString(s"${char} \n"))

val runnableGraph = source.toMat(FileIO.toPath(Paths.get("~/Downloads/results.txt")))(Keep.right)

runnableGraph.run()

The file is already created by the location I set in the code. I do not terminate the actor system, so definitely it has enough time to write all of List elements to the file.

But unfortunately, nothing happens

1

1 Answers

2
votes

Use the expanded path to your home directory instead of the tilde (~). For example:

val runnableGraph =
  source.toMat(
    FileIO.toPath(Paths.get("/home/YourUserName/Downloads/results.txt")))(Keep.right)

runnableGraph.run()