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.
@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();
do PHP: File file = new File(this.getDataFolder(), "config.yml");if(!file.exists()) { file.mkdirs; file.createNewFile();}
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(); }
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.
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.
@KeybordPiano459 Nah. You can store the files anywhere you want and then just copy them when you need it.