Trying to add info (highscorelist) to a .txt file + sorting, without removing existing data
<p><em>This is for a uni-assignment.</em></p>

<p>So, where do I begin?</p>

<p><strong>The task:</strong> The assignment is to make a high schore-list that is a external .txt-file. The .txt-file can only have 5 different top scores, that means if I add a high score that's higher than the 5th place-high scorer that one needs to be deleted and replaced with the new high score. </p>

<p>If you click the class-name you'll get redirected to a pastie-link that includes the code.</p>

<p><strong>The problem(s):</strong> I can not for the life of me get the code to add text without removing current text. The current statement of the code is maybe a wrong way of dealing with the problem, I dont know. I've tried several ways and none seemed to work for me (Or I was doing wrong). Sorting the list should not be a problem since I've done that in a recent assignment.  </p>

<p>Anyways, enough chit-chat, let's get to business.</p>

<p>My main:</p>

<pre><code>    public class main {

    public static void main(String[] args) {
        menu menu = new menu();
        menu.display();

    }
}
</code></pre>

<p><a href="http://pastie.org/6035175" rel="nofollow">My menu:</a></p>

<pre><code>import java.util.*;

public class menu {
    highscores highscores = new highscores();
    private Scanner input = new Scanner(System.in);

    public void display() {
        System.out.println("Make your selection!");
        System.out.println("Select an option: \n" + "  1) Insert new score\n"
                + "  2) Print list\n" + "  3) Reset list \n" + "  4) Quit\n ");

        int selection = input.nextInt();
        input.nextLine();

        switch (selection) {
        case 1:
            highscores.enterScore();
            break;
        case 2:
            highscores.printList();
            break;
        case 3:
            highscores.resetList();
            break;
        case 4:
            System.out.println("Exiting program...");
            System.exit(1);
        default:
            System.out.println("Try Again!"); 
            break;

        }

    }

}
</code></pre>

<p><a href="http://pastie.org/6035178" rel="nofollow">My high score-list</a></p>

<pre><code>import java.io.*;
import java.util.*;

public class highscores {

    public void enterScore() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter the players name!: ");
        String name = scan.nextLine();
        System.out.println("Enter the players score!: ");
        String score = scan.nextLine();
        System.out.println("Player " + name + " got: " + score
                + " points. Great job!");
        try {
            File file = new File("HighScores.txt");
            PrintWriter writer;
            writer = new PrintWriter(file);
            writer.println("Player name: " +name +" - " +"Player score:" +score);
            writer.close();
        } catch (Exception e) {
            System.out.println("Error #1");
        }
    }


    public void printList() {
        try {
            File file = new File("Highscores.txt");
            Scanner scanner;
            if (file.exists()) {
                scanner = new Scanner(file);
                for (int i = 0; i &lt; 5; ++i) {
                    String line = scanner.nextLine();
                    System.out.println(line);
                }
            } else {
                System.out.println("Error #2");
            }
        } catch (Exception e) {
            System.out.println("Error #1");
        }
    }

    public void resetList() {
        try {
            File file = new File("Highscores.txt");
            PrintWriter writer;
            writer = new PrintWriter(file);
            for (int i = 0; i &lt; 5; ++i) {
                writer.println("Player name: x - Player score: x ");
            }
            writer.close();
        } catch (Exception e) {
            System.out.println("Error #1");
        }

    }
}
</code></pre>

<p>Is there ANY way of saving this code and using it for this assignment?</p>
