Scala- writing list to file using foreach
<p>I'm trying to write a list I have into a file and I'm trying to it with the foreach call, as can be done with println.
this works:</p>

<pre><code>list.foreach(println)
</code></pre>

<p>but this won't work:</p>

<pre><code>val file = "whatever.txt"
val writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)))
list.foreach(writer.write)
</code></pre>

<p>I've tried some other ways to print to a file and in all of them had no luck,
what an I doing wrong?</p>