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. Offline

    Proxygames14

    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. Offline

    AlvinB

    @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. Offline

    Proxygames14

    Thanks, This method works perfect!
     
  4. Offline

    AlvinB

  5. 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"));
     
  6. Offline

    Proxygames14

    It worked for me!
     
  7. Offline

    AlvinB

    @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?
     
  8. Offline

    blueye_

  9. Offline

    AlvinB

    @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.
     
  10. 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