?? studentdaofromfile.java
字號:
package com.tarena.exam.dao;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.HashSet;
import com.tarena.exam.model.Student;
public class StudentDaoFromFile implements StudentDao{
private String fileName;
public StudentDaoFromFile(String fileName){
this.fileName=fileName;
//????
}
public Student getStudent(int id, String passwd) {
FileInputStream fis=null;
ObjectInputStream ois=null;
HashSet<Student> hs=null;
try {
fis=new FileInputStream(fileName);
ois=new ObjectInputStream(fis);
hs=(HashSet<Student>)ois.readObject();
for(Student s:hs){
if(s.getId()==id && s.getPasswd().equals(passwd)){
return s;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -