我有JTextArea
当我将此数据写入文本文件时,它会在同一行上打印所有数据:
如何使文本文件的输出与文本区域中的输出相同,分为两行?
文本区域的代码,并将数据写入文本。
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);
}
}
});
答案 0 :(得分:0)
在最后一次.write后使用:
writer.newLine();