Help with reading file

Discussion in 'Plugin Development' started by jpjunho, Dec 8, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    jpjunho

    Hello guys. Im doing a plugin where i put players in list depending on their permissions and then I am saving those lists on a file. However, I cant load it. When I save it, the text file is saved like this:

    group*
    uuid!
    uuid!
    group*
    uuid!

    When I try to read it, I set a string and then when iterating through the lines I set the string to the group im interating:
    Code:
    public static void loadPermissions(){
            try(BufferedReader br = new BufferedReader(new FileReader(saveTo))) {
    
                String permission = null;
    
                for(String s; (s = br.readLine()) != null; ) {
                    if(s.endsWith("\\*")){
                        s.replaceAll("\\*", "");
                        permission = s;
                    }else if(s.endsWith("\\!")){
                        s.replaceAll("\\!", "");
                        if(permission.equalsIgnoreCase("dono")){
                            dono.add(s);
                        }
                        if(permission.equalsIgnoreCase("mod")){
                            mod.add(s);
                        }
                        if(permission.equalsIgnoreCase("vip")){
                            vip.add(s);
                        }
                        if(permission.equalsIgnoreCase("normal")){
                            normal.add(s);
                        }
                    }
                }
                FileOutputStream writer = new FileOutputStream(saveTo);
                writer.write(("").getBytes());
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    But when it tries to read the name the String permission is still null.
    Please help me! Thank you.
     
  2. Offline

    timtower Administrator Administrator Moderator

    bwfcwalshy likes this.
  3. Offline

    jpjunho

    This one is supposed to be just the first file, I want to create multiple ones and I thought this way was the easiest one.
     
  4. Offline

    timtower Administrator Administrator Moderator

    YML has getStringList
     
  5. Offline

    DoggyCode™

    If you really don't wanna use YML, you can use JSON


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page