Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I append to a file in Scala?

Tags:

scala

I would like to write a method similar to the following

def appendFile(fileName: String, line: String) = { } 

But I'm not sure how to flesh out the implementation. Another question on here alludes to Scala 2.9 capabilities but I could not find further details.

like image 706
deltanovember Avatar asked Jul 29 '11 07:07

deltanovember


People also ask

How to append to a file in scala?

nsc. io. File File("filename"). writeAll("hello!") // or appendAll("hello!")


1 Answers

There is no scala-specific IO implementation at the moment, although I understand one written by Jesse Eichar is in incubation. I'm not sure, to what extent this makes use of the new File (path) API in JDK7. Because of this, for now I would go with the simple Java:

val fw = new FileWriter("test.txt", true) try {   fw.write( /* your stuff */) } finally fw.close()  
like image 62
oxbow_lakes Avatar answered Sep 22 '22 18:09

oxbow_lakes