title: deleting a row of line in a text file using java
body: <p>I'm having a hard time deleting a row of lines in a text file, I've use this code but i end up deleting all the lines instead, need some help.                </p>
  
  <pre class="lang-java prettyprint-override"><code>    try //vacation leave/
  {
      File inputFile = new File("Adlawan" + code1);
      File tempFile = new File("AdalwanTempFile");
  
      BufferedReader reader = new BufferedReader(new FileReader(inputFile));
      BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
  
      String lineToRemove = "AdlawanJan2012";
      String currentLine;
  
      while((currentLine = reader.readLine()) != null)
      {
          //trim newline when comparing with lineToRemove
          String trimmedLine = currentLine.trim();
          if(trimmedLine.equals(lineToRemove)) 
          {
           writer.write(currentLine); 
          }
      }   
      writer.close();
      reader.close();
  
      if(!inputFile.delete())
      {
          JOptionPane.showMessageDialog(null, "Could not rename file");
          return;
      }
      if(!tempFile.renameTo(inputFile))
          JOptionPane.showMessageDialog(null, "Could not rename file");
  
  
  }
  catch(Exception e)
  {
      JOptionPane.showMessageDialog(null, " ");
  }
  </code></pre>
  
  <p>The data on the file looks like this:</p>
  
  <p>AdlawanJan2012  Vacation-Leave-Credits  -0.6875<br>
  AdlawanFeb2012  Vacation-Leave-Credits  -0.6875<br>
  AdlawanMar2012  Vacation-Leave-Credits  -0.6875</p>
  
  <p>Desired result after trimming the lines:</p>
  
  <p>AdlawanFeb2012  Vacation-Leave-Credits  -0.6875<br>
  AdlawanMar2012  Vacation-Leave-Credits  -0.6875</p>
  
  <p>Thank you...</p>