コード例 #1
0
  public List<Employee> getAllData() {
    BufferedReader read = null;
    List<Employee> listOfEmployees = new ArrayList<Employee>();
    String[] listOfFiles;
    listOfFiles = pathToFolderWithEmployees.list();

    for (int i = 0; i < listOfFiles.length; i++) {
      try {
        Employee tempEmployee = new Employee();
        read = new BufferedReader(new FileReader(pathToFolderWithEmployees + "/" + listOfFiles[i]));

        tempEmployee.setID(Integer.parseInt(read.readLine()));
        tempEmployee.setName(read.readLine());
        tempEmployee.setLastName(read.readLine());
        tempEmployee.setAddress(read.readLine());
        tempEmployee.setAge(Integer.parseInt(read.readLine()));
        tempEmployee.setCurrentPaymentBalance(Integer.parseInt(read.readLine()));
        listOfEmployees.add(tempEmployee);

        read.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
      System.out.println();
    }

    return listOfEmployees;
  }
コード例 #2
0
  public Employee getSpecificEmployeeData(int id) {
    BufferedReader read = null;
    Employee tempEmployee = new Employee();
    try {
      read = new BufferedReader(new FileReader(pathToFolderWithEmployees + "/" + id + ".txt"));

      tempEmployee.setID(Integer.parseInt(read.readLine()));
      tempEmployee.setName(read.readLine());
      tempEmployee.setLastName(read.readLine());
      tempEmployee.setAddress(read.readLine());
      tempEmployee.setAge(Integer.parseInt(read.readLine()));
      tempEmployee.setCurrentPaymentBalance(Integer.parseInt(read.readLine()));

      read.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return tempEmployee;
  }