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

Neysa ·
更新时间:2024-09-20
· 817 次阅读

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/下面并没有照片

在这里插入图片描述

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

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

学会记录自己的问题


作者:499 ls 599



main exception IN file input

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章