[scala] How to write to a file in Scala?

If you are anyways having Akka Streams in your project, it provides a one-liner:

def writeToFile(p: Path, s: String)(implicit mat: Materializer): Unit = {
  Source.single(ByteString(s)).runWith(FileIO.toPath(p))
}

Akka docs > Streaming File IO