title: Java: retrieve and replace the last line in a text file
body: <p>What is the most efficient way of retrieving and replacing the last line of a text file (in Java 1.4) that could potentially contain millions of lines? Code examples I have seen so far have needed to iterate through the entire file line-by-line before determining if the last line was reached.</p>
  
  <p>A similar question was asked about <a href="https://stackoverflow.com/questions/202148/replace-first-line-of-a-text-file-in-java" title="Replace first line of a text file in Java">replacing the first line in a text file in Java</a>, but an adapted solution would still require traversing the entire file with a <code>BufferedReader</code> to determine the last line in the file.</p>