您能否告知我下面的代码缺少什么?我的代码正在运行,但它没有写入文件。通过文本字段输入 where。下面是我所拥有的。
public class JFrameNewAccount extends javax.swing.JFrame {
ArrayList<BankAccount> list = new ArrayList<BankAccount>();
BankAccount account = new BankAccount();
public JFrameNewAccount() {
initComponents();
}
private void btnSaveAActionPerformed(java.awt.event.ActionEvent evt) {
account.setAccountName(txt_accountname.getText());
account.setAccountNo(txt_accountnumber.getText());
String fileName = "bank.txt";
FileWriter file = null;
try {
file = new FileWriter(fileName,true);
PrintWriter pw = new PrintWriter(file);
for(BankAccount str: list) {
pw.println(str);
}
pw.flush();
pw.println("\n");
} catch(FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, "Can't create your account!");
} catch (IOException ex) {
Logger.getLogger(JFrameNewAccount.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
file.close();
} catch (IOException ex) {
Logger.getLogger(JFrameNewAccount.class.getName()).log(Level.SEVERE, null, ex);
}
}
请指教。