I am using eclipse and I use the following code to load my image from a folder.
getClass().getResource("/images/image.jpg").getFile())
The image folder is located inside the bin folder in the project folder. It works fine when loading in eclipse, but when I export it to a jar it does not load. I have tried puting the image folder in all possible places in the jar, but it does not.
How do I load an image folder in a jar?
You can use getResourceAsStream()
method instead to get InputStream
instance with your file data.
UPDATE: Loading of files from a jar happens with the help of class loader. And it can give you instance of InputStream (not FileInputStream) of any internal resource (be it image file or sound file or text file). File writing shouldn't work inside jar.