我想保存我在文本字段中写的任何内容,并删除程序在单击搜索按钮后找到的行。为什么它不起作用?这是我的两个按钮:
private class dDelete implements ActionListener {
public void actionPerformed (ActionEvent e) {
HM.remove((String)result.getText());
}
}
private class sSave implements ActionListener {
public void actionPerformed (ActionEvent e) {
Set <String> ISet = HM.keySet();
Iterator itr = ISet.iterator();
String tuple = "";
java.io.File iwrite = new java.io.File("c:\\temp\\savetest.txt");
if (iwrite.exists()){
System.out.println("The file exists");
System.exit(0);
}
java.io.PrintWriter output = null;
try {
output = new java.io.PrintWriter(iwrite);
} catch(Exception ex) {
ex.printStackTrace();
}
while (itr.hasNext()) {
String Keys = (String)itr.next();
String val = HM.get(Keys);
tuple = Keys + " " + val;
output.print(tuple);
}
}
}