title: Delete last line in text file
body: <p>I am tying to erase the last line in a text file using Java; however, the code below deletes everything.</p>
  
  <pre><code>public void eraseLast()
  {
      while(reader.hasNextLine()) {
          reader.nextLine();
  
          if (!reader.hasNextLine()) {
              try {
                  fWriter = new FileWriter("config/lastWindow.txt");
  
                  writer = new BufferedWriter(fWriter);
                  writer.write("");
                  writer.close();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>