写了个学生信息管理系统,录入信息没什么问题,重复输入学号也有提示。但是查询信息时总是显示未找到学号,即使刚录入完也显示没找到,不知道咋回事,是否和文件刷新有关呢??请教各位大神!!
录入部分的代码:
try {
FileOutputStream fout=new FileOutputStream("学生信息.txt");
ObjectOutputStream out = new ObjectOutputStream(fout);
学生信息表.put(学号, student);
out.writeObject(学生信息表);
fout.close();
out.close();
}
catch(Exception ee)
{}
查询部分的代码:
if(学号.length()!=0)
try
{
FileInputStream fin=new FileInputStream(file);
ObjectInputStream in=new ObjectInputStream (fin);
学生信息表=(HashMap<String,Student>)in.readObject();
fin.close();
in.close();
}
catch(Exception ee)
{}
if((学生信息表!=null)&&(学生信息表.containsKey(学号)))
{
Student s=(Student)(学生信息表.get(学号));
name.setText(s.getName().toString());
major.setText(s.getMajor().toString());
grade.setText(s.getGrade().toString());
birthday.setText(s.getBirthday().toString());
}