Solved How to saveResource() for .yml resource in plugin subfolder?

Discussion in 'Plugin Development' started by Proxygames14, Aug 18, 2017.

Thread Status:
Not open for further replies.
  1. Im making a plugin! ect.
    And I wanna make a subfolder in my plugins/<plugin> folder called GUI
    Path = plugins/<plugin>/GUI

    I wanna put a file into that folder!
    If im using the saveResource I didnt allow to use that method!
    So my question is

    How to store the default data into a yml.file that exitst in a plugin subfolder?
     
  2. @Proxygames14
    You can just manually recreate the method but use a different file. The JavaPlugin class even provides a getResource() method which returns an InputStream, allowing for a nice one liner using Apache Commons IO:
    Code:java
    1. FileUtils.copyToFile(this.getResource("yourResource.yml"), new File("myFolder/yourResource.yml"));
    That is of course assuming you are in your main class, if you are anywhere else, just replace 'this' with your plugin instance.
     
  3. Thanks, This method works perfect!
     
  4. Offline

    blueye_

    This won't work for me. I think you mean

    Code:java
    1. FileUtils.copyInputStreamToFile(this.getResource("yourResource.yml"), new File("myFolder/yourResource.yml"));
     
  5. It worked for me!
     
  6. @blueye_
    What do you mean it doesn't work? It works for me on 1.12.1. Could it be that you're using an outdated version which doesn't have this version of Apache Commons IO?
     
  7. Offline

    blueye_

  8. @blueye_
    Well, I don't know what Apache Commons IO version is packaged in CraftBukkit, but that is not the case: [​IMG]
    Clearly, both methods close the InputStream.
     
  9. Offline

    blueye_

    @AlvinB
    Ok, you're right. Nevermind.

    Edit: But in the second one var0 never gets closed ...
     
    Last edited: Aug 18, 2017
Thread Status:
Not open for further replies.

Share This Page