Search code examples
javaswingfile-iojtextarea

How to get specified line in JTextArea


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.


Solution

  • You can use JtextArea's write method to do this

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