Skip to content

Instantly share code, notes, and snippets.

@number23
Created March 20, 2017 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save number23/ef1afd0be477cf6136eb471d7965f0b7 to your computer and use it in GitHub Desktop.
Save number23/ef1afd0be477cf6136eb471d7965f0b7 to your computer and use it in GitHub Desktop.
writeStringToFile in Scala
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