[SOLVED] Accessing a file within the .jar?

Discussion in 'Plugin Development' started by kSafin, Jun 18, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    kSafin

    Hello.

    Up until now, I've had a class that initialized all the default configs for my plugin. Basically the class is just a bunch of .set calls hard coded with the default data.

    I now want to just include the default configs as files in my .jar, and then copy them over to the plugins directory on the server.

    Any suggestion on how to access items from the .jar? I planned to use Files.copy(from,to) to copy the file(s), I just don't know what the "from" aka source path for these files is.

    Update: Solved it. For anyone curious, I just did this to get the plugin folder path and just appended my jar as the file and continued on from there:

    Code:
    int sepInd = this.getDataFolder().getAbsolutePath().lastIndexOf(File.separator);
                String path = this.getDataFolder().getAbsolutePath().substring(0,sepInd);
    EDIT: Not even necessary. Just do this.getDataFolder() & append ".jar"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  2. Offline

    petteyg359

    1. Files is Java 7 only.
    2. getClass().getResourceAsStream("config.yml")
     
  3. Offline

    kSafin

    Yeahh that's what I ended up doing.

    Just came back to this post to clear that up, but you've got it covered :p
     
Thread Status:
Not open for further replies.

Share This Page