关于javax.imageio.IIOException: Can't read input file!的问题
今天在跟着视频学习ssm的时候,出现的问题
使用Thumbnails做图片处理时,代码如下:
String basepath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
Thumbnails.of(new File("D:/xiaohuangren.jpg")).size(200, 200).watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File(basepath+"/watermark.jpg")),0.25f).outputQuality(0.8f).toFile("D:/xiaohuangrennew.jpg");
报从异常如下:
Exception in thread "main" javax.imageio.IIOException: Can't read input file!at javax.imageio.ImageIO.read(ImageIO.java:1301)at com.imooc.o2o.util.ImageUtil.main(ImageUtil.java:17)
经过查阅资料后,在控制台打印输出看看basepath,发现了问题所在,
/E:/%e7%a1%95%e5%a3%ab%e6%9c%9f%e9%97%b4%e8%87%aa%e5%ad%a6/SSM_eclipse/o2o/target/classes/
是路径中出现的中文导致的乱码,对basepath做以下处理即可
basepath=URLDecoder.decode(basepath,"utf-8");