Solved java.io.FileNotFoundException (No such file)

Discussion in 'Spigot Plugin Development' started by snakedoctor101, Mar 9, 2018.

Thread Status:
Not open for further replies.
  1. I am currently trying to make a plugin with more than two custom configs, but when I try to load up my server it broadcasts an error

    Error:
    Code (Text):
    [04:06:33 WARN]: java.io.FileNotFoundException: plugins/AdminEssentials/alts.yml (No such file or directory)
    [04:06:33 WARN]:        at java.io.FileInputStream.open0(Native Method)
    [04:06:33 WARN]:        at java.io.FileInputStream.open(FileInputStream.java:195)
    [04:06:33 WARN]:        at java.io.FileInputStream.<init>(FileInputStream.java:138)
    [04:06:33 WARN]:        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:167)
    [04:06:33 WARN]:        at adminEssentials.Main.loadalts(Main.java:82)
    [04:06:33 WARN]:        at adminEssentials.Main.onEnable(Main.java:32)
    [04:06:33 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    [04:06:33 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332)
    [04:06:33 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404)
    [04:06:33 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:342)
    [04:06:33 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:314)
    [04:06:33 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:720)
    [04:06:33 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:544)
    [04:06:33 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25)
    [04:06:33 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140)
    [04:06:33 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620)
    [04:06:33 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:606)
    [04:06:33 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:372)
    [04:06:33 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:336)
    [04:06:33 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629)
    [04:06:33 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537)
    [04:06:33 WARN]:        at java.lang.Thread.run(Thread.java:745)
    Main class:

    Code (Text):
    package adminEssentials;

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;

    import org.bukkit.Bukkit;
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin {
       
        public static Main plugin;
        private File l = null;
        public YamlConfiguration lang = new YamlConfiguration();


        private File a = null;
        public YamlConfiguration alts = new YamlConfiguration();
       
        @Override
        public void onEnable() {
            plugin = this;
            a = new File(getDataFolder(), "alts.yml");
            l = new File(getDataFolder(), "logs.yml");
            mkdir();
            load();
            saveDefaultConfig();
            mkdiralts();
            loadalts();
            saveDefaultConfig();
            getConfig().options().copyDefaults(true);
            saveConfig();
           
           
            Bukkit.getServer().getPluginManager().registerEvents(new MOTD(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new Logs(), this);
           
            getCommand("logs").setExecutor(new Logs());
            getCommand("broadcast").setExecutor(new Broadcast());
            getCommand("motd").setExecutor(new MOTD());
            getCommand("alts").setExecutor(new Alts());
            System.out.println("Admin Essentials has been enabled.");
        }
        private void mkdir() {
            if(!l.exists()) {
                saveResource("logs.yml", false);
            }
        }
        public void load() {
            try {
                lang.load(l);
               
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
        public YamlConfiguration logs() {
            return lang;
        }
        public void save() {
            try {
                lang.save(l);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
       
        private void mkdiralts() {
            if(!l.exists()) {
                saveResource("alts.yml", false);
            }
        }
        public void loadalts() {
            try {
                alts.load(a);
               
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
        public YamlConfiguration alt() {
            return alts;
        }
        public void savealts() {
            try {
                alts.save(a);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
       

    }
     
    In my file system, I have my alts.yml and my logs.yml.
     
  2. When you do saveDefaultConfig(); you still need the file in your project to export. If in IntelliJ, make it in you resources directory. If I’m Eclipse, in the src folder.
     
  3. My alts.yml file is in my src folder.
     
  4. saveDefaultConfig(); only creates a file called config.yml. You may need to add other methods. Search “Bukkit Configuration API” on google and find it on the Bukkit Wiki. They have great examples.
     
  5. Go here and check out the section on mirroring the JavaPlugin implementation.

    JavaPlugin#saveDefaultConfig is not going to apply to all YAML files found in the JAR, just the default config.ymk.
     
  6. Thank you that worked.
     
    • Like Like x 1
Thread Status:
Not open for further replies.

Share This Page