title: Append Lines using BufferedReader and FileWriter
body: <p>I'm trying to parse the code in a file and copy it to a newly created file with the relevant modifications.</p>
  
  <p>However, in the new file all that appears is the final line from the original file.</p>
  
  <p>How do I ensure all the lines get copied to the new file, and not just the last one?</p>
  
  <p>Note: I want a new file to be created every time I run this program, so this question isn't about the FileWriter constructor with 'true' passed in as shown below</p>
  
  <pre><code>FileWriter fw = new FileWriter(newFile.txt, true);
  </code></pre>
  
  <p>Here is the relevant piece of code:</p>
  
  <pre><code>try (BufferedReader bufferedReader = new BufferedReader(new FileReader(args[0]));
          FileWriter fileWriter = new FileWriter(myNewFile.txt)) {
  
          while (bufferedReader.readLine() != null) {
              String currentLine = bufferedReader.readLine();
              fileWriter.write(currentLine);
          }
  </code></pre>
  
  <p>myNewFile.txt only contains the last line of text from the file passed in to the BufferedReader. I don't know of any append functions provided by the FileWriter class.</p>
  
  <p>Thanks</p>
  
  <p>EDIT (SOLUTION):</p>
  
  <p>The problem was resulting from the initialization of currentLine in the while loop. I changed it to</p>
  
  <pre><code>String currentLine;
  while ((currentLine = bufferedReader.readLine()) != null) {
      fileWriter.write(currentLine);
  }
  </code></pre>