I have a piece of code that prints text from a file in a JTextArea called textArea.
Unfortunately, the method I use goes line by line (not perfect), so I need to add each line with \ n
Now thatβs fine, but at the end a new line is created.
The code I have is as follows:
class menuOpen implements ActionListener {
public void actionPerformed(ActionEvent e)
{
try {
File filePath = new File("c:\\test.txt");
FileInputStream file = new FileInputStream(filePath);
BufferedReader br = new BufferedReader(new InputStreamReader(file));
String displayText;
while ((displayText = br.readLine()) != null) {
textArea.append(displayText + "\n");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
Can someone help me get rid of this last line?
tag
source
share