Anonymous user
File input/output: Difference between revisions
→{{header|Scala}}: Exception-handling added
(→{{header|Scala}}: Exception-handling added) |
|||
Line 1,877:
[[Category:Scala Implementations]]
{{libheader|Scala}}
<lang scala>import java.io.{ FileNotFoundException, PrintWriter }
object FileIO extends App {
try {
val MyFileTxtSource = scala.io.Source.fromFile("input.txt")▼
val MyFileTxtTarget = new PrintWriter("output.txt")
val str = MyFileTxtSource.mkString▼
▲ val MyFileTxtSource = scala.io.Source.fromFile("input.txt")
MyFileTxtTarget.close()▼
▲ val str = MyFileTxtSource.mkString
MyFileTxtSource.close()▼
}
} catch {
▲ MyFileTxtTarget.close()
case e: FileNotFoundException => println(e.getLocalizedMessage())
▲ MyFileTxtSource.close()
}
}</lang>
|