在简单的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结束
读取工作正常,但在按下“保存”时写入将执行以下操作:
新的部分和值被写入内存(我可以重新加载它们),但文件不会更新,并保持不变。
我遗漏了什么?
发布于 2012-07-19 21:38:10
您忘记了以下代码:
try {
fontOption.store(new FileOutputStream("config/font.conf"));
} catch(IOException e) {
System.err.println("font: cannot load font.conf or default.conf");
}..。即存储在文件中的更改。
https://stackoverflow.com/questions/7141924
复制相似问题