title: Modify a .txt file in Java
body: <p>I have a text file that I want to edit using Java.  It has many thousands of lines.  I basically want to iterate through the lines and change/edit/delete some text.  This will need to happen quite often.</p>
  
  <p>From the solutions I saw on other sites, the general approach seems to be:</p>
  
  <ul>
  <li>Open the existing file using a BufferedReader</li>
  <li>Read each line, make modifications to each line, and add it to a StringBuilder</li>
  <li>Once all the text has been read and modified, write the contents of the StringBuilder to a new file</li>
  <li>Replace the old file with the new file</li>
  </ul>
  
  <p>This solution seems slightly "hacky" to me, especially if I have thousands of lines in my text file.</p>
  
  <p>Anybody know of a better solution?</p>