Search code examples
javaiopathrelative-path

FileReader relative path


I have a library, ShaderUtils, that I use in my games. Now, when I go to export my games with this library, it doesn't work correctly because the ShaderUtils try to load my shaders through a relative path. How can I fix this? I want it to load it like this:

image = ImageIO.read(Level.class.getClassLoader().getResourceAsStream("heightmap.bmp"));

I'm currently doing this:

BufferedReader reader = new BufferedReader(new FileReader(fragmentLoc));

I need the bufferedReader, but how can I change it so it will load like the image file?


Solution

  • new BufferedReader(
        new InputStreamReader(
            Level.class.getClassLoader().getResourceAsStream("your_resource")
        )
    );