Exception in thread "main" javax.imageio.IIOException: Can't read input file!

Exception in thread “main” javax.imageio.IIOException: Can’t read input file!:无法读取输入文件!

原可以从两个方面分析:

  • 路径中文乱码问题
  • target/classes文件夹中并没有找到图片

加粗样式看下代码:

public class ImageUtils {
    private static  String basePath=Thread.currentThread().getContextClassLoader().getResource("").getPath();
    public static void main(String[] args) throws Exception {
        System.out.println("basePath = " + basePath);
        Thumbnails.of(new File("E:\\ccc\\s2.jpg"))
                .size(1800, 1900)
                .watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File(basePath + "/3.jpg")), 0.7f)
                .outputQuality(0.9f)
                .toFile("E:\\ccc\\NEWs2.jpg");
    }
}

运行结果在这里插入图片描述

假设原因是第一种(解决):

路径乱码:basePath=URLDecoder.decode(basePath,"utf-8");

在这里插入图片描述

运行解决:在这里插入图片描述




假设原因是第二种(解决):target/classes/下面并没有照片

在这里插入图片描述

手动粘贴添加上去
在这里插入图片描述

运行解决:
在这里插入图片描述




学会记录自己的问题




发布了43 篇原创文章 · 获赞 28 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/weixin_44519467/article/details/104766034