imageio.IIOException: Can't read input file

前端 未结 3 1288
鱼传尺愫
鱼传尺愫 2020-12-06 00:31

I\'ve started Java a week ago, and now I would like to insert an image into my window. Whatever I try I keep having this in Eclipse: javax.imageio.IIOException: Can\

3条回答
  •  一向
    一向 (楼主)
    2020-12-06 00:58

    The problem is that you're looking at nothing before the image, so it's looking into a folder that isn't there to find it.

    You have to create a folder to store the images in your project, and then call to it, your folder name in front of the image name. e.g.

    ImageIO.read(new File("Folder/Image.png"));
    

    Otherwise you can find the image by going through the entire directory, which isn't a good way as it takes longer, and when you move your project it won't be a working link as the directory will be different. For example:

    ImageIO.read(new File("D:/eclipse/Workspace/Project/Folder/Image.png"));
    

    Creating a folder in your project so its on the same level as the source folder in the directory and call to it for the image, like so:

    Folder structure;

    settings

    src

    Image Folder

    bin

提交回复
热议问题