How to copy files from jar to the plugin folder?

Discussion in 'Spigot Plugin Development' started by Scrapnix, Apr 27, 2017.

  1. Hey there, I have a very complex question.
    I want to know how to copy files from an intern folder in the jar file (For example from from /com/Scrapnix/name/afunnyfolder/file.schematic) to a extern plugin folder
    (I want to copy a schematic into the /plugins/PLUGINNAME/schematics/file.schematic)
    Does someone know how to copy the file?

    I hope someone can help me :)
  2. Do you mean Copy a File from 1 Plugin Source Code into another Plugin Source Code? Or you asking for just copying a file into another dataFolder of another Plugin
  3. There's a JavaPlugin#getResource() method that returns an InputStream. Convert that into a file and save it somewhere.
    • Agree Agree x 1
  4. @KingDragonRider @Phloxz
    No, I want to copy a file from the jar into the plugin-folder, the /plugins/PLUGINNAME/ folder.
  5. So you mean something like this right?

    Code (Text):

    try {
                InputStream stream = mainClass.getResource("FILENAME");
                FileUtils.copyInputStreamToFile(stream, new File(mainClass.getDataFolder(),"PLUGINFILENAME"));
            } catch (IOException e) {