Reputation: 1262
I am so incredibly confused by this. I've struggled with this before, but once I figured it out, I didn't really have any more problems. But now, it's shown up again. Basically, I have some code which reads a file in as an Image. However, only certain images are readable. Specifically, I can only access images which have been added to the project folder after I refactored to include all files in the source folder (they had previously been outside, but still included in the JAR). I've since managed to fix it by creating copies of the problem folders, deleting the originals, then effectively renaming the copies to the same name as the originals, but I'm still curious as to why this would happen. Anyone have an idea?
Upvotes: 0
Views: 590
Reputation: 109557
One should verify the jar by opening it with 7zip, Winzip or so.
In the same jar, a class can use getResourceAsStream
with an URL (path separator /
, not \\
). A relative URL when the image is in the same package or subpackage path. An absolute URL "/..."
otherwise.
Important is that the path is case-sensitive - not as Windows file names. This can be tricky, as if the file also is on the class path outside the jar, then on Windows (but not Linux) a wrong case will seem okay.
Upvotes: 1