comparison chapter9/WithPrintWriter.scala @ 0:b316eec6fa7a draft default tip

add sample files
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Jan 2013 16:41:46 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b316eec6fa7a
1 import java.io.File
2 import java.io.PrintWriter
3
4 object WithPrintWriter {
5 def withPrintWriter(file: File, op: PrintWriter => Unit) {
6 val writer = new PrintWriter(file)
7 try {
8 op(writer)
9 } finally {
10 writer.close()
11 }
12 }
13 def main(args: Array[String]) {
14 withPrintWriter(
15 new File("date.txt"),
16 writer => writer.println(new java.util.Date)
17 )
18 }
19 }
20
21