try {
String fileName = " ";
// FileReader reads text files in the default encoding.
FileReader reader = new FileReader(fileName);
// read as strings
Scanner in = new Scanner(reader);
String finalValues = "";
while (in.hasNextLine()) {
finalValues = in.nextLine();
txtArea.setText(finalValues);
System.out.println(finalValues);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
The code above is to read all the values from a file to a text area. Sorry I did not put the actual file name there. I'm able to use System.out.println()
to print out all the values. But every time I try to set the values to the text area, only the last value of the file is displayed in the text area.
What am I missing?