[SOLVED] getDataFolder() problems.

Discussion in 'Plugin Development' started by Cirno, Mar 2, 2012.

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

    Cirno

    I'm trying to use this.getDataFolder() in this kind of way:
    File pws = new File(this.getDataFolder() + "/plugins/AdminSecurity", "pws.md5");

    But whenever I add a string after getDataFolder(), it inserts a null right there.
    Anyway to remove the null?

    Things I've Tried:
    String.valueOf(getDataFolder()); (Makes the entire path before the new adding string null)
     
  2. Either just use getDataFolder() by itself to get the folder of your plugin, or do it directly "plugins/AdminSecurity"
     
  3. Offline

    Cirno

    Now it returns the folder Craftbukkit's in.
     
  4. dont use this.getDataFolder().

    Only use getDataFolder() + File.seperator + pws.md5
     
  5. Offline

    Cirno

    Oh! I didn't realize File.seperator...

    EDIT:
    File pws = new File(getDataFolder() + File.separator + "plugins" + File.separator + "AdminSecurity", "pws.md5");
    Returning:
    19:36:03 [INFO] [AdminSecurity] Created pws.md5 in C:\Users\Cirno\Desktop
    \Plugin Testing\null\plugins\AdminSecurity\pws.md5
    And then IOException, cannot find the file

    File pws = new File(getDataFolder() + File.separator, "pws.md5");
    Same resaults.

    It seems whenever you try to add something to getDataFolder(), it returns the folder in which CraftBukkit is in, and adds "null" at the end.

    MeneXia
    manniL
    I had to hardcode the directory in. Thanks for trying guys :p. Solved.
     
  6. getDataFolder() already returns a File class and it's pointing to the relative "plugins/PluginName" folder... I know that for sure, I'm using it in my released plugins, as everybody does.

    Also, you can just use .toString() instead of String.valueOf().
     
  7. Offline

    mykoxaxoxa

    If the getDataFolder() is inside onEnable it will return the plugin directory :D
     
  8. Or use:
    Code:java
    1. File outFile = new File(plugin.getDataFolder().getAbsolutePath(), fileName + ".csv");

    if you prefer absolute file paths.
     
Thread Status:
Not open for further replies.

Share This Page