title: Remove last character while writing to a text file
body: <p>I am writing the contents of the array to a text file in a comma-separated form. Here is my Scala code:</p>
  <pre><code>import java.io.FileWriter
  import scala.util.Random
  
  val N = 1000000
  val writer = new FileWriter(&quot;file.txt&quot;)
  val res = Random.shuffle(1 to N)
  for (i &lt;- 0 until res.length) {
    writer.write(res(i) + &quot;,&quot;)
  }
  writer.close()
  </code></pre>
  <p>This code works fine but also adds a comma at the end like:</p>
  <pre><code>12,11,9,....,23,56,
  </code></pre>
  <p>I want output so that comma is not there at last place</p>
  <pre><code>12,11,9,....,23,56
  </code></pre>
  <p>How can I achieve this?</p>