Created
March 20, 2017 17:12
-
-
Save number23/ef1afd0be477cf6136eb471d7965f0b7 to your computer and use it in GitHub Desktop.
writeStringToFile in 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
import scala.language.reflectiveCalls | |
import java.io.{File, FileWriter} | |
def using[A <: {def close() : Unit}, B](resource: A)(f: A => B): B = | |
try f(resource) finally resource.close() | |
def writeStringToFile(file: File, data: String, appending: Boolean = false) = | |
using(new FileWriter(file, appending))(_.write(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment