java - Cannot read input file for image in Eclipse -
here code:
bufferedimage downarrow; bufferedimage downleftarrow; bufferedimage downrightarrow; bufferedimage leftarrow; bufferedimage rightarrow; bufferedimage uparrow; bufferedimage upleftarrow; bufferedimage uprightarrow; public directionpanel() { try{ downarrow = imageio.read(new file(("images/downarrow.png"))); downleftarrow = imageio.read(new file(("images/downleftarrow.png"))); downrightarrow = imageio.read(new file(("images/downright.png"))); leftarrow = imageio.read(new file(("images/leftarrow.png"))); rightarrow = imageio.read(new file(("images/rightarrow.png"))); uparrow = imageio.read(new file(("images/uparrow.png"))); upleftarrow = imageio.read(new file(("images/upleftarrow.png"))); uprightarrow = imageio.read(new file(("images/uprightarrow.png"))); }catch(ioexception whoops){ system.out.println(whoops); } }
it works in compiler, when try run it, says "javax.imageio.iioexception: can't read input file!"
here file system:
project | |____src | |____mapdata | |____file | |____images | |____downarrow.png | |____downleftarrow.png | |____etc.
what going wrong? tried follow previous answers problem, , am.
i suggest put images in resources folder (if working ide).
then use imageio this:
bufferedimage img = imageio.read(directorypanel.class.getclassloader().getresourceasstream("images/downarrow.png"));
then path reads image <resources-root>/images/downarrow.png
. otherwise file path relative execution directory is.
Comments
Post a Comment