Writing multiline JTextArea content into file
问题 I have to write the content of textarea into a file with line breaks. I got the output like, it is written as one string in the file. public void actionPerformed(ActionEvent ev) { text.setVisible(true); String str= text.getText(); System.out.println(str); try { BufferedWriter fileOut = new BufferedWriter(new FileWriter("filename.txt")); fileOut.write(str); fileOut.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } Example Output should be: I am King. but it is showing: IamKing.