Reputation: 33
When I run my jar file, i get a javax.imageio.IIOException: Can't read input file!
But the file is in the jar!
the code:
try {imgs.put("player1" , ImageIO.read(new File("/car1.png")));}
catch (IOException e) {System.out.println(e);}
I have tried to put car1.png
everywhere in the jar file but its not working.
Upvotes: 3
Views: 2913
Reputation: 20800
You probably want to do this instead.
InputStream is = getClass().getResourceAsStream("car1.png");
ImageIO.read(is);
Upvotes: 3