title: How to replace last line of the file with a new text?
body: <p>I am appending a file in scala, and I want to replace the last line of the file with a new text. I know how to append to a file, but I can't figure out how to overwrite the last line.</p>
  
  <p>I am appending like this:</p>
  
  <pre><code>val fw = new FileWriter("src/file.txt", true) ;
  fw.write("new item");
  </code></pre>
  
  <p>Could anybody help?</p>