spring mvc 上传图片(二)

2014-11-24 09:01:48 · 作者: · 浏览: 4
nputStream(picPath);
int n = 0;
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
byte[] b = new byte[4096];
try {
while ((n = imgis.read(b)) != -1) {
out.write(b, 0, n);
}
} finally {
if (imgis != null) {
imgis.close();
}
}
buf = out.toByteArray();
}catch(IOException e){
logger.error(e.getMessage());
}
return buf;
}
public static void showPic(HttpServletResponse response,byte[] b) {
try{
ServletOutputStream outputStream=response.getOutputStream();
response.reset();
response.setContentType("image/jpeg");
try {
outputStream.write(b, 0, b.length);
outputStream.flush();
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}catch(IOException e){
logger.error(e.getMessage());
}
}