Jump to content

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")
val MyFileTxtTarget = new PrintWriter.print("output.txt"str)
 
MyFileTxtTarget.close()
val str = MyFileTxtSource.mkString
MyFileTxtSource.close()
MyFileTxtTarget.print(str)
}
 
} catch {
MyFileTxtTarget.close()
case e: FileNotFoundException => println(e.getLocalizedMessage())
MyFileTxtSource.close()
}
}</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.