IO流讀取圖片


/**
*  
* @param imgName
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/IoReadImage/{imgName}", method = RequestMethod.GET)
public String IoReadImage(@PathVariable String imgName, HttpServletRequest request, HttpServletResponse response)
throws IOException
{
ServletOutputStream out = null;
FileInputStream ips = null;
try
{
//獲取圖片存放路徑 
String imgPath = "C:\\Users\\booway\\Desktop\\" + imgName + ".png";
ips = new FileInputStream(new File(imgPath));
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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM