Scala: write string to file in one statement

后端 未结 14 1211
星月不相逢
星月不相逢 2020-11-29 17:31

For reading files in Scala, there is

Source.fromFile(\"file.txt\").mkString

Is there an equivalent and concise way to write a string to fi

14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 17:37

    One also has this format, which is both concise and the underlying library is beautifully written (see the source code):

    import scalax.io.Codec
    import scalax.io.JavaConverters._
    
    implicit val codec = Codec.UTF8
    
    new java.io.File("hi-file.txt").asOutput.write("I'm a hi file! ... Really!")
    

提交回复
热议问题