iam trying to write texts from jtextarea and should save it as a textfile as it is.But when run the program the texts is writing in a single line not writing line by line.
For Example:
My input:
abcd eghi asdasddkj but getting output like this
abcdeghiasdasddkj Here is my code:
private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) { try { // TODO add your handling code here: String text = jTextArea1.getText(); File file = new File("D:/sample.txt"); FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pl=new PrintWriter(bw); pl.println(text); System.out.println(text); pl.close(); } catch (IOException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } }
JTextComponentread(Reader, Object)&write(Writer)..