日期:2014-05-17  浏览次数:21201 次

javax.imageio.IIOException: Can't read input file!
java得到根目录下的图片路径BufferedImage companyImg2 = ImageIO.read(new File(img2));不能读出来。求解

------解决方案--------------------
你先检查img2这个路径给的是绝对路径还是相对路径!可能还是路径没有给对!!
------解决方案--------------------
Java code


String binPath=System.getProperty("user.dir");
String filePath=binPath.substring(0, binPath.lastIndexOf("\\"))+File.separator+"webapps"+File.separator+"项目名"+File.separator+"图片文件名"+File.separator+"图片名";

------解决方案--------------------
估计路径不对

你先试试直接在浏览器上输入

http://localhost:8080/项目名/图片文件名/图片名

可以正常显示么。。。
------解决方案--------------------
不要localhost !~~
------解决方案--------------------
探讨

http://localhost:8080/项目名/图片文件名/图片名 在浏览器上是可以正常显示的