2

I can't use scalax because it is in a state between sbt 0.7.7 and sbt 0.11.2 and will not install on windows. (it is missing org.scala-tools.sbt#sbt_2.7.7;0.4.7-p10 even though I have downloaded that and changes scripts to match - newbie well out of his depth).

I can find no examples in the web without scalax.

All I want to do is write some lines of text to a file. However I don't want to have all lines in memory at once.

Can someone point me at an example?

Scala 2.9, Windows 7 - 64 bit.

Ian
  • 1,941
  • 2
  • 20
  • 35
  • I a previous answer, I showed how to write (or read) simple files without hassle: http://stackoverflow.com/questions/6879427/scala-write-string-to-file-in-one-statement/ – paradigmatic Mar 14 '12 at 13:03

1 Answers1

5

The easiest thing to do would probably be using java.io.PrintWriter like so:

scala> val pw = new java.io.PrintWriter("/tmp/foo.txt")
pw: java.io.PrintWriter = java.io.PrintWriter@1e1ff563

scala> pw.println("Hello")

scala> pw.close()

You might want to look up PrintWriter here.

fotNelton
  • 3,844
  • 2
  • 24
  • 35
  • Glad I could help. Since I assume that you're fairly new to Scala, please allow me to hint you at [this nice compilation](http://stackoverflow.com/tags/scala/info) of questions and answers. – fotNelton Mar 14 '12 at 12:58
  • Great list - thanks. And your right - newbie on his first program in Scala, with no Java background :) – Ian Mar 14 '12 at 13:46