Skip to content

Instantly share code, notes, and snippets.

@jiminoc
Created September 16, 2011 17:32
Show Gist options
  • Save jiminoc/1222631 to your computer and use it in GitHub Desktop.
Save jiminoc/1222631 to your computer and use it in GitHub Desktop.
Loan Pattern using BufferedWriter
/**
* we're going to receive an injected output buffer back to our curried function so we can just write lines
* to the output file, the resource will be flushed and closed for us at the end of the run so we don't have to
* worry about resource management
*/
@Test
def workWithBufferedWriterTest() {
val tmpDir = System.getProperty("java.io.tmpdir")
val tmpFilename = tmpDir + "/scalatowntest.log"
println("writing to file: " + tmpFilename)
LoanPattern.withBufferedWriter(tmpFilename) {
ob => {
ob.write("hi temp file!!!")
ob.newLine()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment