Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package resources;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Data {
- //this class for login only
- public Data(){ //Default constructor
- }
- //Staff id
- public ArrayList<Staff> getStaffID() { //arraylist method
- ArrayList<Staff> staffIDList = new ArrayList<Staff>(); //create arraylist
- Scanner input; //scanner obj
- try {
- input = new Scanner(new BufferedReader(new FileReader("staff.txt"))); //get staff file
- //store staff info in arraylist
- input.nextLine();
- while (input.hasNext()) {
- String temp[] = input.nextLine().split(","); //split
- Staff staff = new Staff();
- staff.setStaffID(temp[0]);
- staff.setStaffName(temp[1]);
- staff.setGender(temp[2]);
- staff.setJobTitle(temp[3]);
- staff.setStaffPWD(temp[4]);
- staffIDList.add(staff);
- }
- input.close(); //close scanner
- } catch (FileNotFoundException error) { //print warning if file not found
- System.out.println("File not found!");
- error.printStackTrace();
- }
- return staffIDList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment