Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package vn.webapp.controller.cp; import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Valid; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import java.util.Date; import org.joda.time.DateTime; import org.joda.time.Days; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.json.JSONArray; import org.json.JSONObject; /** * Customize */ import vn.webapp.controller.BaseWeb; import vn.webapp.service.AcademicYearService; import vn.webapp.service.RegularCourse.ExamService; import vn.webapp.service.RegularCourse.ExamStatusService; import vn.webapp.service.RegularCourse.RegularCourseService; import vn.webapp.service.RegularCourse.RegularCourseTimetableEntryService; import vn.webapp.service.RegularCourse.RegularCourseTimetableService; import vn.webapp.service.RoomClusterService; import vn.webapp.service.RoomsService; import vn.webapp.service.RegularCourse.RegularCourseTimetableInterfaceService; import vn.webapp.service.RegularCourse.RegularCourseTimetableStatusService; import vn.webapp.validation.ExamValidation; import vn.webapp.validation.ExamValidationFromSIS; import vn.webapp.validation.FileValidation; import vn.webapp.validation.QueryRoomValidation; import vn.webapp.validation.RegularTimetableValidation; import vn.webapp.validation.RoomEditValidation; import vn.webapp.validation.RoomValidation; import vn.webapp.model.AcademicYear; import vn.webapp.model.RoomCluster; import vn.webapp.model.Rooms; import vn.webapp.model.RegularCourse.AjaxFileUpload; import vn.webapp.model.RegularCourse.Exam; import vn.webapp.model.RegularCourse.ExamStatus; import vn.webapp.model.RegularCourse.OverlapExam; import vn.webapp.model.RegularCourse.RegularCourse; import vn.webapp.model.RegularCourse.RegularCourseTimetable; import vn.webapp.model.RegularCourse.RegularCourseTimetableEntry; import vn.webapp.model.RegularCourse.RegularCourseTimetableInterface; import vn.webapp.model.RegularCourse.RegularCourseTimetableStatus; import vn.webapp.utilities.StringConvert; @Controller("cpExams") @RequestMapping(value = { "/cp" }) public class ExamController extends BaseWeb { @Autowired private ExamService examService; @Autowired private RoomsService roomsService; @Autowired private RoomClusterService roomClusterService; @Autowired private AcademicYearService academicYearService; @Autowired private RegularCourseService regularCourseService; @Autowired private RegularCourseTimetableStatusService regularCourseTimetableStatusService; @Autowired private RegularCourseTimetableInterfaceService regularCourseTimetableInterfaceService; @Autowired private ExamStatusService examStatusService; /** * * @param model * @return */ @RequestMapping(value = "/Exams", method = RequestMethod.GET) public String Exams(ModelMap model, HttpSession session) { /* * Get current user name and role */ String currentUserName = session.getAttribute("currentUserName").toString(); String userRole = session.getAttribute("currentUserRole").toString(); // Get list regulartimetables List<ExamStatus> examStatusList = examStatusService.loadEXSList(); /* * Put data back to view */ model.put("examStatusList", examStatusList); return "cp.exams"; } @RequestMapping(value = "/ExamDetail/{id}", method = RequestMethod.GET) public String ExamDetail(ModelMap model, @PathVariable("id") int Id, HttpSession session) { ExamStatus EXS = examStatusService.loadByID(Id); List<Exam> examList = examService.loadExamList(EXS.getEXS_AcaYear_Code(), EXS.getEXS_Semester()); model.put("examList", examList); model.put("examStatus", EXS); return "cp.examDetail"; } @RequestMapping(value = "/DeleteExams/{id}", method = RequestMethod.GET) public String DeleteExams(ModelMap model, @PathVariable("id") int Id, HttpSession session) { ExamStatus eXS = examStatusService.loadByID(Id); String AcaYear = eXS.getEXS_AcaYear_Code(); int semester = eXS.getEXS_Semester(); examStatusService.remove(Id); List<ExamStatus> examStatusList = examStatusService.loadEXSList(); model.put("examStatusList", examStatusList); model.put("status", "? xa thnh cng lch thi" + " h?c k " + Integer.toString(semester) + " nm h?c " + AcaYear); return "cp.exams"; } @RequestMapping(value = "/AddExam", method = RequestMethod.GET) public String AddExam(ModelMap model, HttpSession session) { /* * Get current user name and role */ String currentUserName = session.getAttribute("currentUserName").toString(); String userRole = session.getAttribute("currentUserRole").toString(); // Get list reportingYear List<AcademicYear> academicYearList = academicYearService.list(); AcademicYear curAcadYear = academicYearService.getCurAcadYear(); List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>(); for (AcademicYear aY : academicYearList) { if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code())) otherAcadYearList.add(aY); } /* * Put data back to view */ model.put("academicYearList", otherAcadYearList); model.put("curAcadYear", curAcadYear); model.put("examFormAdd", new ExamValidation()); return "cp.addExam"; } @RequestMapping(value = "/CheckOverlapExamFromExcel", method = RequestMethod.GET) public String checkOverlapExamFromExcel(ModelMap model, HttpSession session) { /* * Get current user name and role */ String currentUserName = session.getAttribute("currentUserName").toString(); String userRole = session.getAttribute("currentUserRole").toString(); model.put("checkOverlapExamFromExcel", new FileValidation()); return "cp.checkOverlapExamFromExcel"; } /*@RequestMapping(value = "/EditExam/{id}", method = RequestMethod.GET) public String EditRoom(ModelMap model,@PathVariable("id") int examId, HttpSession session) { * Get current user name and role Exam exam = examService.loadByID(examId); model.put("exam", exam); model.put("examFormEdit", new ExamEditValidation()); return "cp.editExam"; }*/ /*@RequestMapping(value = "/QueryRoom", method = RequestMethod.GET) public String QueryRoom(ModelMap model, HttpSession session) { * Get current user name and role List<AcademicYear> academicYearList = academicYearService.list(); AcademicYear curAcadYear=academicYearService.getCurAcadYear(); List<AcademicYear> otherAcadYearList=new ArrayList<AcademicYear>(); for (AcademicYear aY:academicYearList){ if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code())) otherAcadYearList.add(aY); } model.put("queryRoom", new QueryRoomValidation()); model.put("academicYearList", otherAcadYearList); model.put("curAcadYear", curAcadYear); return "cp.queryRoom"; } */ /** * Save a room */ @RequestMapping(value = "saveExam", method = RequestMethod.POST) public String saveExam(HttpServletRequest request, @Valid @ModelAttribute("examAdd") ExamValidation examValidation, BindingResult result, Map model, HttpSession session) { /* * Get list of paper category and journalList */ /* * Put data back to view */ if (result.hasErrors()) { return "cp.addExam"; } else { /* * Prepare data for inserting DB */ /** * Uploading file */ MultipartFile sourceUploadFile = examValidation.getExamFileUpload(); String fileName = sourceUploadFile.getOriginalFilename(); String sourceUploadFileSrc = ""; String StatusMessages = ""; try { //Creating Date in java with today's date. Date currentDate = new Date(); //change date into string yyyyMMdd format example "20110914" SimpleDateFormat dateformatyyyyMMdd = new SimpleDateFormat("HHmmssddMMyyyy"); String sCurrentDate = dateformatyyyyMMdd.format(currentDate); byte[] bytes = sourceUploadFile.getBytes(); String path = request.getServletContext().getRealPath("uploads"); File dir = new File(path + "/exam"); if (!dir.exists()) { dir.mkdirs(); } // Create a file String currentUserName = session.getAttribute("currentUserName").toString(); fileName = currentUserName + "_" + sCurrentDate + "_" + fileName; File serverFile = new File(dir.getAbsolutePath() + File.separator + fileName); if (serverFile.exists()) { sourceUploadFileSrc = dir.getAbsolutePath() + File.separator + fileName; } // Save data into file BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); List<ExamStatus> EXS_List = examStatusService.loadEXSList(); boolean isToAdd = true; for (ExamStatus EXS : EXS_List) { if ((EXS.getEXS_AcaYear_Code().equals(examValidation.getAcademicYear())) && (EXS.getEXS_Semester() == examValidation.getSemester())) { isToAdd = false; break; } } if (isToAdd) examStatusService.save(examValidation.getAcademicYear(), examValidation.getSemester(), 1); List<ExamInfo> examinfos = ReadExamInfos .readFileExcel(dir.getAbsolutePath() + File.separator + fileName); int cnt = 0; try (DataOutputStream out = new DataOutputStream( new FileOutputStream("examUploadStatus.bin", false))) { out.writeInt(examinfos.size()); for (ExamInfo ei : examinfos) { cnt++; out.writeInt(cnt); if (ei != null) { String RCE_Code = examValidation.getAcademicYear() + "-" + examValidation.getSemester() + "-" + ei.getClassCode() + "-" + ei.getGroup() + "-" + ei.getTurn() + "-" + ei.getRoom(); Exam ex = examService.loadByCode(RCE_Code); if (ex == null) { examService.save(RCE_Code, examValidation.getAcademicYear(), examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(), ei.getCourseName(), Integer.parseInt(ei.getWeek()), Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(), ei.getGroup(), ei.getRoom()); } else { if (!((ex.getRCE_Date().equals(ei.getDate())) && (ex.getRCE_Day() == Integer.parseInt(ei.getDay())) && (ex.getRCE_Week() == Integer.parseInt(ei.getWeek())) && (ex.getRCE_Room_Code().equals(ei.getRoom())))) { examService.edit(RCE_Code, examValidation.getAcademicYear(), examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(), ei.getCourseName(), Integer.parseInt(ei.getWeek()), Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(), ei.getGroup(), ei.getRoom()); StatusMessages += "Cp nht thnh cng lp " + ex.getClass() + " nhm " + ex.getRCE_Group() + " thi\n"; } } } } StatusMessages += "Thm mi thnh cng " + cnt + " lp thi\n"; model.put("status", StatusMessages); /** * Preparing data for adding into DB */ //if(i_InsertAPaper > 0){ //model.put("status", "Successfully saved a paper: "); //model.put("status",StatusMessages); System.out.println(StatusMessages); return "redirect:" + this.baseUrl + "/cp/Exams.html"; //} } catch (Exception e) { model.put("status", "You failed to upload " + fileName + " => " + e.getMessage()); } } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } catch (IOException e) { System.out.println(e.getMessage()); } finally { try (DataOutputStream out = new DataOutputStream( new FileOutputStream("examUploadStatus.bin", false))) { } catch (Exception e) { } } return "cp.addExam"; } } @RequestMapping(value = "/OverlapExamListFromExcel", method = RequestMethod.POST) public String overlapExamListFromExcel(HttpServletRequest request, @Valid @ModelAttribute("checkOverLapExam") FileValidation fileValidation, BindingResult result, Map model, HttpSession session) { /* * Get list of paper category and journalList */ /* * Put data back to view */ if (result.hasErrors()) { return "cp.checkOverLapExamFromExcel"; } else { /* * Prepare data for inserting DB */ /** * Uploading file */ MultipartFile sourceUploadFile = fileValidation.getFileUpload(); String fileName = sourceUploadFile.getOriginalFilename(); String sourceUploadFileSrc = ""; String StatusMessages = ""; try { //Creating Date in java with today's date. Date currentDate = new Date(); //change date into string yyyyMMdd format example "20110914" SimpleDateFormat dateformatyyyyMMdd = new SimpleDateFormat("HHmmssddMMyyyy"); String sCurrentDate = dateformatyyyyMMdd.format(currentDate); byte[] bytes = sourceUploadFile.getBytes(); String path = request.getServletContext().getRealPath("uploads"); File dir = new File(path + "/exam"); if (!dir.exists()) { dir.mkdirs(); } // Create a file String currentUserName = session.getAttribute("currentUserName").toString(); fileName = currentUserName + "_" + sCurrentDate + "_" + fileName; File serverFile = new File(dir.getAbsolutePath() + File.separator + fileName); if (serverFile.exists()) { sourceUploadFileSrc = dir.getAbsolutePath() + File.separator + fileName; } // Save data into file BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); HashMap<String, ArrayList<String>> m = ReadExamInfos .Exam2TimeMapping(dir.getAbsolutePath() + File.separator + fileName); AcademicYear curAcadYear = academicYearService.getCurAcadYear(); List<RegularCourseTimetableInterface> RCTTI_List = regularCourseTimetableInterfaceService .loadRCTTIList(curAcadYear.getACAYEAR_Code()); HashSet<String> exWeekSet = new HashSet<String>(); for (String key : m.keySet()) { exWeekSet.add(key.split("_")[1]); } for (RegularCourseTimetableInterface rCTTI : RCTTI_List) { List<String> weeks = StringConvert.ExpandToListString(rCTTI.getWeek()); int day = rCTTI.getDay(); String room = rCTTI.getRoom(); String[] slots = StringConvert.Expand(rCTTI.getSlot()).split(","); int startTurn = 0, endTurn = 0; try { startTurn = (Integer.parseInt(slots[0]) - 1) / 3 + 1; endTurn = (Integer.parseInt(slots[slots.length - 1]) - 1) / 3 + 1; } catch (NumberFormatException e) { startTurn = endTurn = 0; } for (String exWeek : exWeekSet) { if (weeks.contains(exWeek)) { for (int i = startTurn; i <= endTurn; i++) { String key = room + "_" + exWeek + "_" + day + "_Kp " + i; if (m.containsKey(key)) { ArrayList<String> val = m.get(key); val.add("Lp h?c: " + rCTTI.getClasscode() + " " + rCTTI.getCoursecode() + " " + rCTTI.getCoursename()); } } } } } ArrayList<OverlapExam> overlapExamList = new ArrayList<OverlapExam>(); ArrayList<String> val = new ArrayList<String>(); for (String key : m.keySet()) { val = m.get(key); if (val.size() >= 2) { int ok = 0; String code = ""; for (String ex : m.get(key)) { String[] tks = ex.split(" "); if (code.equals("")) code = tks[2]; else { if (!code.equals(tks[2])) { ok = 1; break; } } } if (ok == 1) { OverlapExam ovlE = new OverlapExam(); ovlE.setClassExamLst(val); ovlE.setOverlapTime(key); overlapExamList.add(ovlE); } } } System.out.println("Done " + overlapExamList.size()); model.put("status", StatusMessages); model.put("overlapExamList", overlapExamList); System.out.println(StatusMessages); } catch (Exception e) { model.put("status", "You failed to upload " + fileName + " => " + e.getMessage()); } return "cp.overlapExamList"; } } @RequestMapping(value = "/AddExamFromSIS", method = RequestMethod.GET) public String AddExamFromSIS(ModelMap model, HttpSession session) { /* * Get current user name and role */ String currentUserName = session.getAttribute("currentUserName").toString(); String userRole = session.getAttribute("currentUserRole").toString(); // Get list reportingYear List<AcademicYear> academicYearList = academicYearService.list(); AcademicYear curAcadYear = academicYearService.getCurAcadYear(); List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>(); for (AcademicYear aY : academicYearList) { if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code())) otherAcadYearList.add(aY); } /* * Put data back to view */ model.put("academicYearList", otherAcadYearList); model.put("curAcadYear", curAcadYear); model.put("examFormAdd", new ExamValidationFromSIS()); return "cp.addExamFromSIS"; } @RequestMapping(value = "saveExamFromSIS", method = RequestMethod.POST) public String saveExamFromSIS(HttpServletRequest request, @Valid @ModelAttribute("examAdd") ExamValidationFromSIS examValidation, BindingResult result, Map model, HttpSession session) { /* * Get list of paper category and journalList */ /* * Put data back to view */ if (result.hasErrors()) { return "cp.addExam"; } else { String StatusMessages = ""; try { List<ExamStatus> EXS_List = examStatusService.loadEXSList(); boolean isToAdd = true; for (ExamStatus EXS : EXS_List) { if ((EXS.getEXS_AcaYear_Code().equals(examValidation.getAcademicYear())) && (EXS.getEXS_Semester() == examValidation.getSemester())) { isToAdd = false; break; } } if (isToAdd) examStatusService.save(examValidation.getAcademicYear(), examValidation.getSemester(), 1); ReadExamInfos examData = new ReadExamInfos(); List<ExamInfo> examinfos = new ArrayList<ExamInfo>(); String classCode = ""; String courseCode = ""; String courseName = ""; String week = ""; String day = ""; String date = ""; String turn = ""; String slots = ""; String group = ""; String room = ""; String[] tks = examValidation.getAcademicYear().split("-"); Connector cn = new Connector(); String jsonPath = "http://127.0.0.1:9876/getExam?term=" + tks[0] + examValidation.getSemester(); String json = cn.getJson(jsonPath); List<AcademicYear> academicYearList = academicYearService.list(); String firstdateStr = ""; String enddateStr = ""; for (AcademicYear aY : academicYearList) { if (aY.getACAYEAR_Code().equals(examValidation.getAcademicYear())) { firstdateStr = aY.getACAYEAR_FromDate(); enddateStr = aY.getACAYEAR_ToDate(); break; } } DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy"); LocalDate firstdate = fmt.parseLocalDate(firstdateStr); LocalDate enddate = fmt.parseLocalDate(enddateStr); if (json != "") { json = "{ exams : " + json + "}"; //System.out.println(json); try { JSONObject obj = new JSONObject(json); JSONArray exams = obj.getJSONArray("exams"); for (int i = 0; i < exams.length(); ++i) { JSONObject exam = exams.getJSONObject(i); classCode = Integer.toString(exam.getInt("Classid")); courseCode = exam.isNull("CourseID") ? "" : exam.getString("CourseID"); RegularCourse rc = regularCourseService.loadByCode(courseCode); courseName = rc == null ? "" : rc.getRC_Name(); week = exam.getString("WeekName"); day = exam.getString("WeekDayName"); turn = exam.getString("TimeTable"); //date = exam.isNull("DateExam")?"":exam.getString("DateExam"); group = exam.getString("ClassGroup"); room = exam.getString("RoomID"); if (week.contains("T")) week = week.substring(1, week.length()); switch (day.toLowerCase()) { case "th hai": day = "2"; break; case "th ba": day = "3"; break; case "th t": day = "4"; break; case "th nm": day = "5"; break; case "th su": day = "6"; break; case "th by": day = "7"; break; case "ch nht": day = "8"; break; } int weekNum = Integer.parseInt(week); int dayNum = Integer.parseInt(day); date = firstdate.plusDays((weekNum - 1) * 7 + dayNum - 2).toString(fmt); room = room.replace(",", "-"); String[] tokens = turn.split(" "); //kp 1:7h 1,2,3 //kp 2: 9h30 4,5,6 //kp 3: 12h30 7,8,9 //kp 4: 15h 10,11,12 //StartTime = {0645, 0735, 0830, 0920, 1015, 1105, 1230, 1320, 1415, 1505, 1600, 1650, 2130}; //EndTime = {0730, 0820, 0915, 1005, 1100, 1150, 1345, 1405, 1500, 1550, 1645, 1735, 2130}; try { String[] subtokens = tokens[tokens.length - 1].split("-"); int startSlot = Integer.parseInt(subtokens[0]) * 3 - 2; int endSlot = Integer.parseInt(subtokens[subtokens.length - 1]) * 3; slots = Integer.toString(startSlot); for (int i1 = startSlot + 1; i1 <= endSlot; i1++) slots += "," + Integer.toString(i1); } catch (Exception e) { slots = ""; } ExamInfo objExam = new ExamInfo(classCode, courseCode, courseName, week, day, date, turn, slots, group, room); examinfos.add(objExam); } } catch (Exception e) { e.printStackTrace(); examinfos.clear(); } } int cnt = 0; for (ExamInfo ei : examinfos) { //if(cnt++==10) break; if (ei != null) { String RCE_Code = examValidation.getAcademicYear() + "-" + examValidation.getSemester() + "-" + ei.getClassCode() + "-" + ei.getGroup() + "-" + ei.getTurn() + "-" + ei.getRoom(); Exam ex = examService.loadByCode(RCE_Code); if (ex == null) { examService.save(RCE_Code, examValidation.getAcademicYear(), examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(), ei.getCourseName(), Integer.parseInt(ei.getWeek()), Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(), ei.getGroup(), ei.getRoom()); cnt++; } else { if (!((ex.getRCE_Date().equals(ei.getDate())) && (ex.getRCE_Day() == Integer.parseInt(ei.getDay())) && (ex.getRCE_Week() == Integer.parseInt(ei.getWeek())) && (ex.getRCE_Room_Code().equals(ei.getRoom())))) { examService.edit(RCE_Code, examValidation.getAcademicYear(), examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(), ei.getCourseName(), Integer.parseInt(ei.getWeek()), Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(), ei.getGroup(), ei.getRoom()); StatusMessages += "Cp nht thnh cng lp " + ex.getClass() + " nhm " + ex.getRCE_Group() + " thi\n"; } } } } StatusMessages += "Thm mi thnh cng " + cnt + " lp thi\n"; model.put("status", StatusMessages); /** * Preparing data for adding into DB */ //if(i_InsertAPaper > 0){ //model.put("status", "Successfully saved a paper: "); //model.put("status",StatusMessages); System.out.println(StatusMessages); return "redirect:" + this.baseUrl + "/cp/Exams.html"; //} } catch (Exception e) { model.put("status", "Failed to update from SIS => " + e.getMessage()); } return "cp.addExamFromSIS"; } } @RequestMapping(value = "/AjaxExamUploadResponse.json", method = RequestMethod.GET) public @ResponseBody AjaxFileUpload ajaxResponse(ModelMap model, HttpSession session) { /* * Get current user name and role */ String currentUserName = session.getAttribute("currentUserName").toString(); String userRole = session.getAttribute("currentUserRole").toString(); AjaxFileUpload res = new AjaxFileUpload(); // Get list regulartimetables int curNum = 0; try (DataInputStream in = new DataInputStream(new FileInputStream("examUploadStatus.bin"))) { res.setTotalNum(in.readInt()); while (true) curNum = in.readInt(); } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } catch (EOFException e) { res.setCurNum(curNum); } catch (IOException e) { System.out.println(e.getMessage()); } return res; } }