Created
September 16, 2011 17:32
-
-
Save jiminoc/1222631 to your computer and use it in GitHub Desktop.
Loan Pattern using BufferedWriter
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
/** | |
* 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