Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created May 16, 2015 10:37
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 shigemk2/43ea8206d3d3ab45abe8 to your computer and use it in GitHub Desktop.
Save shigemk2/43ea8206d3d3ab45abe8 to your computer and use it in GitHub Desktop.
import java.io._
def withWriter(filename: String)(op: Writer => Unit) {
val writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(filename),"UTF-8"))
// op(writer)だけだと処理されない
try {
op(writer)
} finally {
writer.close()
}
}
withWriter("test.txt"){
writer => writer.write("this is sample")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment