I am reading a 100 MB pict开发者_如何学Goure into my app. It works fine inside Eclipse, but not when I export project to a JAR. Then, I get "Can't read input file!"
Since I need to edit it, I used BufferedImage
.
private String str = "images/1.png";
BufferedImage imageMap;
//in constructor
imageMap = ImageIO.read(new File(str));
I have tried this, but the project image does not load inside Eclipse:
imageMap = ImageIO.read(this.getClass().getClassLoader().getResource(str));
Check you working directory if the image is loaded from the file system. Then you see if your relative path "images/1.png"
is valid. Or you directly check the path of your png
System.out.println(new File("."));
File f = new File("images/1.png");
System.out.println(f.getAbsolutePath());
精彩评论