def scalaWriteExample(outfilename: String): Boolean = { var writer:OutputStreamWriter = null try { val out = new FileOutputStream(new File(outfilename)) writer = new OutputStreamWriter(out, "UTF-8") } catch { case e: Exception => return false } writer.write("Something\n"); writer.close() return true }
Programming Tips - Scala: write to a file with Scala
Date: 2012nov22
Language: Scala
Q. Scala: write to a file with Scala
A. From my reading it seems that the Scala IO package
is fine for input but not mature for output. So I use the Java
classes for output. Here's a example: