How to save all files in a directory etc: /plugins/LOL

Discussion in 'Plugin Development' started by -_Husky_-, Mar 22, 2012.

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

    -_Husky_-

    Title pretty much explains it
     
  2. Offline

    HON95

    Not really.... What files?
     
  3. Offline

    -_Husky_-

    Ok, I have a directory called lol, there are 50 txt files in it(example)
    i want to save them ALL at once without 50 different variables
     
  4. Offline

    HON95

    Umm. If they are already there, they are obviously saved. So I still don't understand what the problem is. Do you have unsaved versions of them in your code or something?
     
  5. Offline

    -_Husky_-

    Yeah i add things to them along the line, and they dont seem to save
     
  6. Offline

    Double0negative

    what are you using to load them? File? Scanner? On of bukkits classes?
     
  7. Offline

    -_Husky_-

    Yamlconfiguration
     
  8. Offline

    HON95

    yamlconfig.save(File file) for saving.
     
  9. Offline

    -_Husky_-

    I dont want to have to do that 50x :/
     
  10. Offline

    HON95

    Use a loop?
     
  11. Offline

    -_Husky_-

    Please demonstrate
     
  12. Offline

    zwap1233

    like HON95 said use a loop. for example a while or for loop!
     
  13. Offline

    HON95

    If you show some code, it would be easier.
     
  14. Offline

    -_Husky_-

    Im not on my computer but, just make 5 files and show me please :)
     
  15. Offline

    LucasEmanuel

    Code:
    for(i = 0 ; i < listOfFiles.length() ; i++) {
        yamlconfig.save(listOfFiles[i]);
    }
    
    I have no experience from saving files in bukkit, but this is what i would do after i read this thread.
     
  16. Offline

    -_Husky_-

    nah, still didn't work, as i need to specify every file, and i dont know the names of them, as they are player names
     
  17. Offline

    comp8nerd4u2

    You can store the names of the players that you need to save data for and then put them into an array. At save, iterate through all the names and save the file with their name and put all their data into their respective files.
     
  18. Offline

    -_Husky_-

    Example please :d
     
  19. Offline

    Lolmewn Retired Staff

    Code:
    File f = new File("plugins/LOL/");
            File[] dir = f.listFiles();
            for(File f : dir){
                //save it
            }
     
  20. Offline

    comp8nerd4u2

    Code:
    public static ArrayList<String> players = new ArrayList<String>();
    // Keep an array list of their yaml configs here as well. I don't know what the associated Object is for it, but i'll throw in this...
    public static ArrayList<YAMLConfigObject> yamlconfigs = new ArrayList<YAMLConfigObject>();
     
     
    // Plugin accumulates a large amount of data on a lot of players
    ...
    // PluginManager calls our onDisable method
    ...
    Iterator<String> playerIterator = players.listIterator();
    Iterator<YAMLConfigObject> yamlconfigIterator = yamlconfigs.listIterator();
    while (playerIterator.hasNext()) {
        String player = playerIterator.next();
        YAMLConfigObject yamlconfig = yamlconfigIterator.next();
        File playerFile = new File(player + ".dat");
        yamlconfig.save(playerFile);
    }    
    Please note: I have absolutely no experience handling YAML loading and saving. However, this is how most configuration utility objects are setup in Java.
     
Thread Status:
Not open for further replies.

Share This Page