title: Deleting a specific line from a text file in Java
body: <p>I am setting up a rank system where each member has a username and a rank. The program reads the username and rank from a text file and assigns it to the user.
  One username and rank per line, such as:</p>
  
  <pre><code>user1 1
  user2 2
  user3 3
  </code></pre>
  
  <p>I have set up a program to add usernames and ranks to the text file, however I cannot seem to figure out how to delete a specific user from the list, such as if I wanted to only delete user 2 and his/her rank and leave the other two, however it is important that afterwards there isn't a blank line left behind.</p>
  
  <p>Just for reference here is the code for how I write it to the file in the first place:</p>
  
  <pre><code>             try {
                   BufferedWriter out = new BufferedWriter(new FileWriter("stafflist.txt", true));
                   for (int i = 0; i &lt; 1; i++) {
                   out.newLine();
                   out.write(target.getUsername() + " " + target.getRights());
                   }
               out.close();
               SerializableFilesManager.savePlayer(target);
                      if (loggedIn) {
                      target.getPackets().sendGameMessage(modString + Utils.formatPlayerNameForDisplay(member.getUsername()) + "!", true);}
               member.getPackets().sendGameMessage(successString + Utils.formatMemberNameForDisplay(target.getUsername()) + " to a Moderator.",true);
               loggedIn = false;
                  } catch (IOException e) {
                  System.out.println("GiveMod - Can't find stafflist.txt");
                  }
               return true;
  </code></pre>