Solved Trying to load my yml config, throws FileNotFound

Discussion in 'BungeeCord Plugin Development' started by Trophonix, Jun 9, 2016.

  1. Hey! I'm pretty new to Bungee, and I'm trying to use the YML config API. I was using this wiki post as a reference.

    Imports:
    Code (Text):
    import com.google.common.io.ByteArrayDataInput;
    import com.google.common.io.ByteArrayDataOutput;
    import com.google.common.io.ByteStreams;
    import net.md_5.bungee.api.connection.ProxiedPlayer;
    import net.md_5.bungee.api.event.PluginMessageEvent;
    import net.md_5.bungee.api.plugin.Listener;
    import net.md_5.bungee.api.plugin.Plugin;
    import net.md_5.bungee.config.Configuration;
    import net.md_5.bungee.config.ConfigurationProvider;
    import net.md_5.bungee.config.YamlConfiguration;
    import net.md_5.bungee.event.EventHandler;
    object/onEnable:
    the private Configuration data; is line 22
    Code (Text):
        private Configuration data;

        @Override
        public void onEnable() {
            getProxy().getPluginManager().registerListener(this, this);
            try {
                if(!getDataFolder().exists())
                    getDataFolder().mkdir();
                data = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "data.yml"));
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    Error:
    Code (Text):
    17:18:21 [SEVERE] java.io.FileNotFoundException: plugins/TeleportBeaconBungee/data.yml (No such file or directory)
    17:18:21 [SEVERE]     at java.io.FileInputStream.open0(Native Method)
    17:18:21 [SEVERE]     at java.io.FileInputStream.open(FileInputStream.java:195)
    17:18:21 [SEVERE]     at java.io.FileInputStream.<init>(FileInputStream.java:138)
    17:18:21 [SEVERE]     at java.io.FileReader.<init>(FileReader.java:72)
    17:18:21 [SEVERE]     at net.md_5.bungee.config.YamlConfiguration.load(YamlConfiguration.java:56)
    17:18:21 [SEVERE]     at net.md_5.bungee.config.YamlConfiguration.load(YamlConfiguration.java:50)
    17:18:21 [SEVERE]     at com.trophonix.teleportbeacon.TeleportBeaconBungee.onEnable(TeleportBeaconBungee.java:30)
    17:18:21 [SEVERE]     at net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:227)
    17:18:21 [SEVERE]     at net.md_5.bungee.BungeeCord.start(BungeeCord.java:267)
    17:18:21 [SEVERE]     at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:55)
    17:18:21 [SEVERE]     at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15)
     
    So... Yeah. Am I supposed to be running something to specifically create the "data.yml"?
    If I do new File(getDataFolder(), "data.yml")).mkdirs(); it makes a directory called "data.yml".
     
    #1 Trophonix, Jun 9, 2016
    Last edited: Jun 10, 2016
  2. The file just doesn't exist. There's a method in the file class called .exists (); and if it returns false, you have to create the file with the method in the file class. I forgot the name but I think it's something like createFile(); then it should work.
    You shouldn't do mkdirs because you don't want data.yml to be a folder.
     
    • Like Like x 1
  3. Oh my gosh... I tried the .createNewFile() thing but I forgot that was inside an if statement checking if the DATA FOLDER doesn't exist (and it did exist because of previous failed attempts). Deeerrrp. ;-; Thanks xD