我試圖將值(在文本區域中鍵入)存儲到txt文件中。以下代碼正在創建program.txt文件,但數據未寫入其中。我究竟做錯了什麼?在.txt文件上寫入數據
如果我想要將這些值保存在用戶指定的.txt文件中,該怎麼辦?
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
o = new BufferedWriter(new FileWriter("program.txt"));
o.write(t1.getText());
o.write(",");
o.write(t2.getText());
o.write(",");
o.write(t3.getText());
o.write(",");
o.write(t4.getText());
o.write(",");
o.write(t5.getText());
o.write(",");
o.write(t6.getText());
o.write(",");
o.write(t7.getText());
o.write(",");
}
catch (IOException e){
e.printStackTrace();
}
工作!謝謝你 –
@ user2003602歡迎您,請不要忘記打勾答案:) – PermGenError
很好的答案。 +1同意,當你有機會時,請[接受](http://meta.stackexchange.com/a/65088/155831)答案。 –