Unable to read input file – read image contained in jar file – Java

I think there are similar problems, but I can't find a solution I'm working on a painting application based on Java swings

InputStream is = this.getClass().getClassLoader().getResourceAsStream("bg3.jpg");
bgfile=ImageIO.read(is);

Bgfile is an object of the bufferedimage class Therefore, once I run as a jar file, I throw the following IOException:

Unable to read input file!

But if I open the jar file with WinRAR, I can find the file bg3.0 in the root directory of the jar file jpg. If I specify the path as "/ BG3. JPG", the jar file itself will not open

So I need some help and explanation Thank you in advance

Solution

The contents of the jar file are case sensitive This may sound stupid, but did you check the file? If you have a file Jpg, then load file Jpg will not work properly Even extensions are case sensitive (file. JPG vs file. JPG)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>