Get text file name from config

Discussion in 'Plugin Development' started by slater96, Jul 27, 2012.

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

    slater96

    I'm trying to get a string from my config for the file.txt name but it gives me an error when I do it.
    Code:
    public void loadFile() {
            File txt = new File(getDataFolder(), this.getConfig().getString("CommandOne" + ".txt"));
            if (!txt.exists()) {
                try {
                    txt.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    Is there any way to do this?
     
  2. Offline

    CorrieKay

    What does it say? code looks fine to me upon a cursory glance.
     
  3. Offline

    slater96

    It gives me this error:
    Code:
    00:42:10 [SEVERE] Error occurred while enabling CommandList v0.1 (Is it up to da
    te?)
    java.lang.NullPointerException
            at java.io.File.<init>(Unknown Source)
            at me.slater96.CommandList.CommandList.loadFile(CommandList.java:37)
            at me.slater96.CommandList.CommandList.setupLoggerEnable(CommandList.jav
    a:48)
            at me.slater96.CommandList.CommandList.onEnable(CommandList.java:27)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:337)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:256)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:238
    )
            at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:552)
            at org.bukkit.Bukkit.reload(Bukkit.java:182)
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    22)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    79)
            at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.
    java:475)
            at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:612)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:581)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    And when i change the plugin bit to whatever.txt it works fine.

    No worries, fixed it :D
    I did this
    Code:
            String root = this.getConfig().getString("CommandOne");
            File txt = new File(getDataFolder(), root + ".txt");
    And then it worked. However, how can I generate multiple txt files using that some load method?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    Jeff.Halbert

    File is usually real touchy for me, maybe you can try leaving the .txt out of the name, and just put it into your code.

    Code:
    public void loadFile() {
      String txt = this.getConfig().getString("commandOne");
      File file = new File(getDataFolder(), txt + ".txt");
      if (!file.exists()) {
        try {
          file.createNewFile();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    =edit=
    LOL, you figured it out as I was writing this :-D
     
Thread Status:
Not open for further replies.

Share This Page