RosettaCodeData/Task/Take-notes-on-the-command-line/Scala/take-notes-on-the-command-line.scala
2023-07-01 13:44:08 -04:00

19 lines
623 B
Scala

import java.io.{ FileNotFoundException, FileOutputStream, PrintStream }
import java.time.LocalDateTime
object TakeNotes extends App {
val notesFileName = "notes.txt"
if (args.length > 0) {
val ps = new PrintStream(new FileOutputStream(notesFileName, true))
ps.println(LocalDateTime.now() + args.mkString("\n\t", " ", "."))
ps.close()
} else try {
io.Source.fromFile(notesFileName).getLines().foreach(println)
} catch {
case e: FileNotFoundException => println(e.getLocalizedMessage())
case e: Throwable => {
println("Some other exception type:")
e.printStackTrace()
}
}
}