Hi I am trying to use the getText()
method from a JTextArea
and write that into a .txt
file. Here is my code:
try {
String = "OrderDetails.txt";
PrintWriter output = new PrintWriter(fileName);
output.println("Customer Details");
// this part is not important
output.println(txtAreaOutput.getText()); //Spits out multiple lines into a single line :(
output.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(FamousFavoriteSubs.class.getName()).log(Level.SEVERE, null, ex);
}
As you can imagine the textarea has multiple rows text and I want to maintain that when I save the text to the .txt file. Is there a way to do this?
The
JTextArea
has a "write" function to which you have to send aBufferedWriter
.Actually this was answered multiple times, so please google the problem before posting here.
Writing JTextArea content into file