我需要从文件中删除某些行,该文件是我从文件读入我的GUI中的联系人列表。当我到达要删除的联系人时,我的程序应该从文件中删除联系人。我试图做到这一点,但它不起作用。从文件中删除行
这是我目前使用的代码:
String temp=txtname.getText();
for (Contact Contact:contacts)
{
if (temp.equals(Contact.getname()));
{
txtname.setText("");
txtsurname.setText("");
txtphone.setText("");
txtmobile.setText("");
txtaddress.setText("");
txtpostcode.setText("");
contacts.remove(Contact);
contacts.remove(Contact);
contacts.remove(Contact);
contacts.remove(Contact);
contacts.remove(Contact);
contacts.remove(Contact);
}
}
我接触类是:我猜它会删除它从ArrayList中
public class Contact {
static void add(String text) {
}
public String name;
public String surname;
public String phone;
public String mobile;
public String address;
public String postcode;
public Contact(){}
public Contact(String name, String surname, String phone,
String mobile, String address, String postcode)
{
this.name = name;
this.surname = surname;
this.phone = phone;
this.mobile = mobile;
this.address = address;
this.postcode = postcode;
}
public String getname()
{
return this.name;
}
public String getsurname()
{
return this.surname;
}
public String getphone()
{
return this.phone;
}
public String getmobile()
{
return this.mobile;
}
public String getaddress()
{
return this.address;
}
public String getpostcode()
{
return this.postcode;
}
public void setname(String name)
{
this.name = name;
}
public void setsurname(String surname)
{
this.surname = surname;
}
public void setphone(String phone)
{
this.phone = phone;
}
public void setmobile(String mobile)
{
this.mobile = mobile;
}
public void setaddress(String address)
{
this.address = address;
}
public void setpostcode(String postcode)
{
this.postcode = postcode;
}
}
,但我不知道程序如何知道要从文件中删除什么。
谢谢。
第4行末尾有一个错位的分号。 – Svante 2009-11-29 16:20:28
真的吗?当它在那里,它不会在它被移除时运作良好,所以去图! – addiosamigo 2009-11-29 18:00:41