使用以下代码,我可以将 program.txt 存储在工作项目文件夹中,但是如何使用 JFileChooser 或任何其他选项将文件保存在选定位置?
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(",");
o.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
});