读取文件中题库信息这一段的思路
//读取目录下全部题库
private static void readAllExam(){
File dir = new File("exam");
for (File file : dir.listFiles()) {
readExam(file);
}
}
//读取文件中题库信息
public static void readExam(File file){
Exam exam = new Exam();
exam.setName(file.getName().substring(0,file.getName().indexOf(".")));
try {
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
while((line = br.readLine()) != null) {
String[] data = line.split(" ");
Question question = new Question(data);
exam.getQuestions().add(question);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
exams.add(exam);
}