创建人 | |
问题标题 | 异常错误 |
问题分类 | 运行出错 |
一级话题 | Type Exception Report Message F:\idearProjects\javaweb\out\artifacts\day_15_responce_war_exploded\火影.jpg (系统找不到指定的文件。) Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception java.io.FileNotFoundException: F:\idearProjects\javaweb\out\artifacts\day_15_responce_war_exploded\火影.jpg (系统找不到指定的文件。) java.base/java.io.FileInputStream.open0(Native Method) java.base/java.io.FileInputStream.open(FileInputStream.java:196) java.base/java.io.FileInputStream.<init>(FileInputStream.java:139) java.base/java.io.FileInputStream.<init>(FileInputStream.java:94) cn.it.down.DownloadServlet.doPost(DownloadServlet.java:28) cn.it.down.DownloadServlet.doGet(DownloadServlet.java:54) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) |
问题补充 | 路径异常,找不到链接的图片的主要路径,获得真实路径的时候出错,无法找到图片位置 |
附件 | String filename = req.getParameter("filename"); // System.out.println(filename); //获得域对象 ServletContext servletContext = this.getServletContext(); //找到那个图片链接的真实路径 String realPath = servletContext.getRealPath( filename); //利用字节流将图片加载进内存 FileInputStream fis = new FileInputStream(realPath); //获取文件的类型 String mimeType = servletContext.getMimeType(filename); |
问题答案 | 真实路径不对外面还有一个文件夹 |
String filename = req.getParameter("filename"); // System.out.println(filename); //获得域对象 ServletContext servletContext = this.getServletContext(); //找到那个图片链接的真实路径 String realPath = servletContext.getRealPath("/img/" + filename); //利用字节流将图片加载进内存 FileInputStream fis = new FileInputStream(realPath); //获取文件的类型 String mimeType = servletContext.getMimeType(filename); |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |