Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package servlet1.webshop;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.StringTokenizer;
- public class UsersList {
- private ArrayList<User> allUsers = new ArrayList<User>();
- public UsersList (String path) {
- BufferedReader in = null;
- try {
- File file = new File (path + "/Users.txt");
- System.out.println(file.getCanonicalPath());
- in = new BufferedReader(new FileReader(file));
- readUsers (in);
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- private void readUsers (BufferedReader in) {
- String line;
- String username = "";
- String password = "";
- StringTokenizer st;
- try {
- while ((line = in.readLine()) != null) {
- line = line.trim();
- if (line.equals("") || line.indexOf("#") == 0)
- continue;
- st = new StringTokenizer(line, ";");
- while (st.hasMoreTokens()) {
- username = st.nextToken().trim();
- password = st.nextToken().trim();
- }
- allUsers.add(new User (username, password));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public List<User> getAllUsers() {
- return allUsers;
- }
- public void setAllUsers(ArrayList<User> allUsers) {
- this.allUsers = allUsers;
- }
- }
Add Comment
Please, Sign In to add comment