I have a JTextArea
When I write this data to text file, it prints all on the same line:
How to make the output of text file to be the same like in text area, on 2 separate lines?
The code of text area, and writing data to text.
JTextArea matrixArea = new JTextArea();
matrixArea.setBounds(139, 63, 337, 111);
dataPanel.add(matrixArea);
JButton sendData = new JButton("Send Data");
sendData.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String nrPatterns = patternText.getText().toString();
String inputTex = inputText.getText().toString();
String otputTex = outputText.getText().toString();
String matrixW = matrixArea.getText().toString();
try {
FileWriter writer = new FileWriter("test.txt", true);
writer.write(nrPatterns);
writer.write(" ");
writer.write(inputTex);
writer.write(" ");
writer.write(otputTex);
writer.write(" ");
writer.write(System.getProperty("line.separator"));
writer.write(matrixW);
writer.close();
JOptionPane.showMessageDialog(window, "Success");
}catch(Exception e){
JOptionPane.showMessageDialog(window, "Error", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});