-2

Using the code below, I am trying to make a log for a plugin, though, every time it makes a entry I want it to go below the other entry. Though, when I test it, it writes the second entry but the first entry gets deleted.

if (commandLabel.equalsIgnoreCase("logmeup")) {
    entry++;
    entry3 = entry * 3;
    FileWriter fw= null;
    File file =null;

    try {
        file = new File("playerLog.txt");
        if(!file.exists()) {
            file.createNewFile();
        }
        fw = new FileWriter(file);
        if (entry == 1) {
            fw.write("Name: " + player.getDisplayName() + "\nIP: " + player.getAddress() + "\nLocation: " + player.getLocation() + "\n");
            fw.close();
        }
        else {
            while (entryloop < entry3) {
                entryloop++;
                fw.write(System.getProperty( "line.separator" ));
            }
            entryloop = 0;
            fw.write("Name: " + player.getDisplayName() + "\nIP: " + player.getAddress() + "\nLocation: " + player.getLocation() + "\n");
            fw.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Will
  • 24,082
  • 14
  • 97
  • 108
  • Pastebin source contains only 26 lines, fix the line number in the question. – Dawid Bugajewski May 17 '15 at 01:48
  • 2
    This is a site where questions and answers that can help all are presented. In order for this question to help future users we ask that you post **all** pertinent information here with your question and not in links. Also, please understand that all who help here are volunteers, and we much appreciate your making it as easy as possible to understand your question, including not making us go to outside sites for information. – Hovercraft Full Of Eels May 17 '15 at 01:49
  • .... so which line is the involved line?? – Hovercraft Full Of Eels May 17 '15 at 01:51

1 Answers1

1

Flaged as dupe yet I will answer it once again: Pass second argument of FileWriter as true to make it go into append mode.

fw = new FileWriter(file,true);
Dawid Bugajewski
  • 365
  • 1
  • 11