问题
Whenever i need to load some image i have difficulties with its path Like i use eclipse and by putting it in src folder and then using this path
ImageIcon = new ImageIcon ("/image.png");
It does not load image i need to put it somewhere in my computer and then copy paste its path ....Its not Actually better option as when i tend to run my code in some other computer i need to change the paths of all images in my code back again please help
Thanks
回答1:
Create "resource" folder into your project folder than paste your image into that folder and try following
imageIcon ii = new imageIcon(getClass().getResource("/image.png"));
Or use bufferedImage like following
BufferedImage bi = ImageIO.read(getClass().getResource("/image.png");
来源:https://stackoverflow.com/questions/46745962/cant-choose-a-default-path-in-java-when-using-imageicon-in-java