comparison chapter9/WithPrintWriter2.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 object WithPrintWriter2 {
2
3 def main(args: Array[String]) {
4 val fiel =new File("data.txt")
5 withPrintWriter(file) {
6 writer => writer.println(new java.util.Data)
7 }
8 }
9
10 def withPrintWriter(file: File)(op: PrintWriter => Unit) {
11 val writer = new PrintWriter(file)
12 try {
13 op(writer)
14 } finally {
15 writer.close()
16 }
17 }
18 }
19