Created
January 14, 2015 13:19
-
-
Save ikenna/248aef91363893149e29 to your computer and use it in GitHub Desktop.
Write to a file 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
def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) { | |
val p = new java.io.PrintWriter(f) | |
try { op(p) } finally { p.close() } | |
} | |
//Usage | |
printToFile(new File("fileName.txt"))(p => p.write("someString")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment