输出图片
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = "D:/andy.jpg"; FileInputStream inputStream = new FileInputStream(path); byte[] bytes = IOUtils.toByteArray(inputStream); resp.getOutputStream().write(bytes); }
先拿到路径
然后获取文件输入流
然后将输入流转为字节数组
然后输出字节数组