@RequestMapping(value = "readImg")
public String readImg(HttpServletRequest request,HttpServletResponse response) throws IOException {
ServletOutputStream out = null;
FileInputStream ips = null;
String url = "D:/one/two.png";
try {
//获取图片存放路径
File file = new File(url);
if(!file.exists()) {
return null;
}
ips = new FileInputStream(file);
response.setContentType("multipart/form-data");
out = response.getOutputStream();
//读取文件流
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = ips.read(buffer)) != -1){
out.write(buffer,0,len);
}
out.flush();
}catch (Exception e){
e.printStackTrace();
}finally {
out.close();
ips.close();
}
return null;
public String readImg(HttpServletRequest request,HttpServletResponse response) throws IOException {
ServletOutputStream out = null;
FileInputStream ips = null;
String url = "D:/one/two.png";
try {
//获取图片存放路径
File file = new File(url);
if(!file.exists()) {
return null;
}
ips = new FileInputStream(file);
response.setContentType("multipart/form-data");
out = response.getOutputStream();
//读取文件流
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = ips.read(buffer)) != -1){
out.write(buffer,0,len);
}
out.flush();
}catch (Exception e){
e.printStackTrace();
}finally {
out.close();
ips.close();
}
return null;
}
Finally, add it to the image path