使用以下代碼我可以將program.txt存儲在工作項目文件夾中,但是如何使用JFileChooser或任何其他選項將文件保存在選定位置?如何使用JFileChooser在所需位置保存.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(",");
o.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
});
[如何保存的文件可能重複做這樣使用JFileChooser?](http://stackoverflow.com/questions/2531037/how-to-save-file-using-jfilechooser) –