Skip to content

Instantly share code, notes, and snippets.

@Yuichiroh
Last active August 29, 2015 14:18
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 Yuichiroh/e1119736ec541bf4785b to your computer and use it in GitHub Desktop.
Save Yuichiroh/e1119736ec541bf4785b to your computer and use it in GitHub Desktop.
def withPrintWriter(file: String)(op: PrintWriter => Unit) {
val writer = new PrintWriter(file)
try op(writer)
finally writer.close
}
withPrintWriter("out.txt") { w =>
w.println("anything you want to write")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment