NaoDesu

Data

Feb 20th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package resources;
  2. import java.io.BufferedReader;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.util.ArrayList;
  6. import java.util.Scanner;
  7.  
  8. public class Data {
  9.     //this class for login only
  10.    
  11.     public Data(){ //Default constructor
  12.        
  13.     }
  14.    
  15.     //Staff id
  16.     public ArrayList<Staff> getStaffID() { //arraylist method
  17.         ArrayList<Staff> staffIDList = new ArrayList<Staff>(); //create arraylist
  18.         Scanner input; //scanner obj
  19.         try {
  20.             input = new Scanner(new BufferedReader(new FileReader("staff.txt"))); //get staff file
  21.            
  22.             //store staff info in arraylist
  23.             input.nextLine();
  24.             while (input.hasNext()) {
  25.                
  26.                 String temp[] = input.nextLine().split(","); //split
  27.                 Staff staff = new Staff();
  28.                 staff.setStaffID(temp[0]);
  29.                 staff.setStaffName(temp[1]);
  30.                 staff.setGender(temp[2]);
  31.                 staff.setJobTitle(temp[3]);
  32.                 staff.setStaffPWD(temp[4]);
  33.                 staffIDList.add(staff);
  34.                
  35.             }
  36.             input.close(); //close scanner
  37.            
  38.         } catch (FileNotFoundException error) { //print warning if file not found
  39.             System.out.println("File not found!");
  40.             error.printStackTrace();
  41.         }
  42.     return staffIDList;            
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment