Tag Archives: javax.imageio.IIOException: Can’t read input file!

javax.imageio.IIOException: Can’t read input file! 23436;”209151;

Open source software supply chain lighting plan, waiting for you>>>

Today, we have a problem. The picture above is

This code is mainly to add a watermark to the image

Later Baidu found that there may be a problem with the path of the picture, because it is a dynamic image address, and then I printed out the address

After checking through the terminal, it was not

Then I found the file in the classes directory

At this time, he realized

Because my picture file was put in the Resources folder of the main folder at the beginning, it will be put in the classes folder when the file is compiled

However, my test code runs in the test folder, and the contents of the Resources folder in the test folder will be placed in the test classes folder

The dynamic path in the code is based on the current running code location, so the path is/users/Huang/ideaprojects/o2o/target/test classes/watermark.png, but the picture is compiled and placed in/users/Huang/ideaprojects/o2o/target/classes/watermark.png, so the error is reported and the file cannot be found

Solution:

I used a rough way to copy the image to test/resources. When compiling, the image will be put in the path of/users/Huang/ideaprojects/o2o/target/test classes. The problem is solved