How to Read a png File Stored Within an Exported jar in Eclipse

32 Views Asked by At

I have watched several videos and visited every stackoverflow thread I could find about reading files from within a jar and none of the methods I have found worked for me.

My most recent attempt was building a ResourceLoader class and it worked just fine in the ide but, when I exported it to a runnable jar it doesn't seem to be able to find the files.

Here is the ResourceLoader class

public final class ResourceLoader {

    public static InputStream load(String path) {
        InputStream input = ResourceLoader.class.getResourceAsStream(path);
        if(input==null) {
            input = ResourceLoader.class.getResourceAsStream(File.separator+path);
        }
        return input;
    }

}
    

My png files are stored in a folder named "textures" and that folder is inside a src folder named "res"

0

There are 0 best solutions below