Q:

Loading .txt file to textarea Java

I have a textarea that loads a specified file.  Everything works well except for that only the last line of the file is output into the textarea.
File f = new File(this.path);

try {
    // Create a Scanner for the file
    Scanner input = new Scanner(f);

    // Read text from the file
    while (input.hasNext()) {
        jTextArea1.setText(input.nextLine());
    }

    // Close the file
    input.close();

} catch (FileNotFoundException fe) {
    fe.printStackTrace();
}

A:

That's because in your while loop you are setting the text, instead of appending to it.
So every time you get a new line of input you override the last one. You are eventually left with only the last line of input.
Use jTextArea1.append(input.nextLine()); instead of jTextArea.setText(...);.

