Failing to open file, am I linking it wrong? Or is Android Studio not seeing it for some reason?

后端 未结 3 431
忘了有多久
忘了有多久 2021-01-27 12:09

I have a simple .txt file with just a couple lines in right now, each line has a word then a comma then another word, representing a very simplistic username , password bank. Fo

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 12:58

    Thanks to @CommonsWare I was able to achieve what I was trying to do by using InputStream and then also IOUtils to read everything into the List.

    try {
            InputStream iS = this.getAssets().open("passwords.txt");
            List user_password = IOUtils.readLines(iS);
    
            @SuppressWarnings("unchecked") List credentials = (List) CollectionUtils.collect(user_password, new Transformer() {
                @Override
                public Object transform(Object input) {
                    String cred = (String) input;
                    String parsed[] = cred.split(",");
                    return new Credentials(parsed[0], parsed[1]);
                }
            });
            user = (Credentials) CollectionUtils.find(credentials, new Predicate() {
                @Override
                public boolean evaluate(Object object) {
                    Credentials c = (Credentials) object;
                    return c.getUserName().equals(userName);
                }
            });
        }catch (IOException e){
            System.out.print(e);
        }
    

提交回复
热议问题