How to get a specific line in JTextArea


This question already has an answer here:

  • Writing multiline JTextArea content into file 1 answer

I would like to write the content of JTextArea into the .txt file but I do not want to loose new line characters. So I want to write it line by line I do not know how to get specified line from the JTextArea.

You can use JtextArea's write method to do this

 JTextArea jArea=new JTextArea();
 //do something............
 BufferedWriter fileOut = new BufferedWriter(new FileWriter(yourFile));