为什么list
即使从文本字段中提取数据后我的也是空的?或者有没有其他方法可以从文本字段中获取值并将它们附加到文件中?任何帮助,将不胜感激。
public class AddUser implements ActionListener
{
Set<UserBean> list = new HashSet<UserBean>();
UserBean user = new UserBean();
Iterator it = list.iterator();
//Irrelevant code
private void saveObject()
{
try
{
FileWriter output = new FileWriter("D://names.csv", true);
if (it.hasNext() == false)
{
System.out.println("empty");
}
while(it.hasNext())
{
UserBean current = (UserBean)it.next();
output.append(current.getLastName());
output.append(",");
output.append(current.getFirstName());
output.append("\n");
}
} catch(Exception e)
{
}
}
public void actionPerformed(ActionEvent ae)
{
Object src = ae.getSource();
if (src == bAdd)
{
user.setFirstName(tfFirst.getText().trim());
user.setLastName(tfLast.getText().trim());
list.add(user);
saveObject();
}