title: Replace strings and save file in Scala
body: <p>I have the following code where I am reading a file and replacing any occurences of "*.tar.gz" file with the new file name provided. Everything works fine and I can see the replaced changes in the console however I am not being able to write a new file with all the changes.</p>
  
  <pre><code>def modifyFile(newFileName: String, filename: String) = {
      Source.fromFile(filename).getLines.foreach { line =&gt;
        println(line.replaceAll(".+\\.tar\\.gz", newFileName.concat(".tar.gz")))
      }
    }
  }
  </code></pre>