Last active
August 14, 2019 07:54
-
-
Save lossyrob/45695e44601d6a9e9077 to your computer and use it in GitHub Desktop.
Read \ Write a text file in one line Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write(path: String, txt: String): Unit = { | |
import java.nio.file.{Paths, Files} | |
import java.nio.charset.StandardCharsets | |
Files.write(Paths.get(path), txt.getBytes(StandardCharsets.UTF_8)) | |
} | |
def read(path: String): String = | |
scala.io.Source.fromFile(path, "UTF-8").getLines.mkString | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @soulmachine