How to read the txt file data into arraylist

后端 未结 2 1176
自闭症患者
自闭症患者 2021-01-07 07:27

This following data is inside the Admin.txt file

id, username, password, name, email, contactNumber, icNumber

AD001|admin|admin|admin|admin@gmail.com         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 07:52

    Perhaps this code can help you

    public static void main(String[] args) throws Exception{
    
          BufferedReader br = new BufferedReader(new FileReader("Admin.txt"));
          ArrayList al = new ArrayList();
          String line = null;
          while ((line = br.readLine()) != null) {
            Admin admin = new Admin();
            String lines[] = line.split("|");
            /*adjust accordingly
            admin.setName(lines[0]);
            admin.setUser(lines[1]);
                ....*/
            al.add(admin);          
          }
          br.close();
    }
    

提交回复
热议问题