Creating and Reading Config File

Discussion in 'Plugin Development' started by ohtwo, Feb 6, 2013.

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

    ohtwo

    Code:
            // Creates a new configuration file if one does not exist
            File configFile = new File(this.getDataFolder() + "/config.yml");
            if(!configFile.exists())
            {
                this.getLogger().info("No configuration file found. Attempting to create one.");
                this.saveDefaultConfig();
            }
    Hey guys. Does this code even make sense? I am able to create a new config file if its missing, but when it comes to loading actual values (e.g. this.plugin.getConfig().getBoolean("debug")), it seems to be loading the default value that's in the jar. I have no problem mutating the values after it has been loaded though...
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    No, all you have to do is call saveDefaultConfig()
     
  3. Offline

    CubixCoders

    ohtwo
    Code:
    File configFile = new File(this.getDataFolder() + "/config.yml");
    
    Bad line^
    That will generate /config.yml in your folder.
    So it will load it from config.yml while you set /config.yml 's data get rid of the /
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    This statement makes no such thing on the file system. Please read the javadoc for File.
     
  5. Offline

    ohtwo

    I guess I just don't understand what's going on with the code. I was expecting there to be some kind of "open" method, and if there was a FileNotFoundException, create a new file.
     
  6. Offline

    teunie75

  7. Offline

    Sagacious_Zed Bukkit Docs

    File IO has been abstracted away for you.
     
Thread Status:
Not open for further replies.

Share This Page