按照简单的 ini4j 教程,我编写了一个类来读取和写入 JDBC 连接。这是我单击对话框按钮时所做的事情:
public void actionPerformed(ActionEvent ae){
JButton b = (JButton)ae.getSource();
if (b == save || b == load) {
try {
Ini ini;
String section = name.getText();
if (b == load) {
System.out.println("Loading " + section);
ini = new Ini(new File(cfgname));
driver.setText(ini.get(section, "Driver"));
url.setText(ini.get(section, "URL"));
username.setText(ini.get(section, "User"));
password.setText(ini.get(section, "Password"));
} else {
System.out.println("Saving " + section);
ini = new Ini(new File(cfgname));
ini.put(section, "Driver", driver.getText());
ini.put(section, "URL", url.getText());
ini.put(section, "User", username.getText());
ini.put(section, "Password", password.getPassword());
ini.store();
} // endif b
} catch (FileNotFoundException fe) {
System.out.println(cfgname + ": not found " + fe);
setVisible(false);
} catch (IOException ioe) {
System.out.println(ioe);
setVisible(false);
} // end try/catch
} else {
id = (ae.getSource() == ok);
setVisible(false);
} // endif b
} // actionPerformed 结束
阅读效果很好,但在点击“保存”时写入会执行以下操作:
新的部分和值被写入内存(我可以重新加载它们)但是文件没有更新并且保持不变。
我错过了什么?