javax.imageio.ImageIO的异常
代码:
String basePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
Thumbnails.of(new File("C:/test/test.jpg")).size(200, 200).watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File(basePath + "/watermark.jpg")),0.25f).outputQuality(0.8f).toFile("C:/test/testnew.jpg");
错误信息:
Exception in thread "main" javax.imageio.IIOException: Can't read input file!at javax.imageio.ImageIO.read(Unknown Source)at com.tbx.o2o.util.ImageUtil.main(ImageUtil.java:18)
原因:
路径获取错误
/D:/Javaee%20_workspaces/o2o/target/classes/
//出现%20的错误
解决方法:
basePath=URLDecoder.decode(basePath,"utf-8");
添加以后:
/D:/Javaee _workspaces/o2o/target/classes/
正常,异常排除