Files Not Generating Folder

Discussion in 'Plugin Development' started by KeybordPiano459, Jul 5, 2012.

  1. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I've got a .txt file that is printed in chat when a command is written, and I want people that download my plugin to be able to edit this .txt file so that they can edit what is there. The .txt file exists, but it doesn't generate a folder so that people can see the .txt file and edit it without decompiling their way into the jar. Can someone tell me how to make a folder generate with this file in it? This will be important for when I make a config.yml.
  2. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @KeybordPiano459
    Make sure that you defined the right file path.
    Code:
    plugin.getDataFolder().mkdir();
    File file = new File(plugin.getDataFolder(), "YourFile.txt");
    if (!file.isFile()) file.createNewFile();
     
    

    This post has been edited 1 time. It was last edited by r0306 Jul 5, 2012.
  3. Offline

    messageofdeath

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    do
    PHP:
    File file = new File(this.getDataFolder(), "config.yml");
    if(!
    file.exists()) {
        
    file.mkdirs;
        
    file.createNewFile();
    }
  4. Offline

    one4me

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hey look at some code I posted in this thread - http://forums.bukkit.org/posts/1196984/, specifically the File Extractor method. It will let you extract a file from a jar, creating a backup if it has already been extracted before, and creating the directory if it hasn't been extracted before.

    But if you only need to get the 'config.yml' from the jar and nothing else, the following code should work.
    Code:
    if(!(new File(this.getDataFolder(), "config.yml")).exists()) {
      saveDefaultConfig();
    }
    

    This post has been edited 2 times. It was last edited by one4me Jul 5, 2012.
  5. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thanks for the help, just one last question. In my java project folder, do I need a folder to keep my files in? Currently I just have my files on the same leves as my src folder.
  6. Offline

    one4me

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You should probably leave the files in the root since using something like saveDefaultConfig() requires it to be in the root and unless you have a ton of files you don't really need to worry about organization being a problem.
  7. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @KeybordPiano459
    Nah. You can store the files anywhere you want and then just copy them when you need it.

Share This Page