我正在尝试将值(在文本区域中键入)存储到 txt 文件中。以下代码正在创建 program.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();
}