图片支持get请求访问

BufferedInputStream in = new BufferedInputStream(doc2.getContent());//读取文件到输入流
OutputStream out = response.getOutputStream();//获取response的输出流
try{
	byte[] buf = new byte[2048];//每次读流的字节数
	int len=0;  
	while((len = in.read(buf))>0)  {  
	       out.write(buf,0,len);//将图片写入到输出流里面不断返回数据给请求源
	}
	in.close();
	out.flush();  
	out.close();
}catch (Exception e) {
	// TODO: handle exception
	LogUtil.error("Get picture with uuid:"+uuid, e);
}finally{
	in.close();
	out.close();
}

主要就是把图片或文件不断写入到response的输出流

上述在文件比较大的时候性能不好

最好加上缓冲bufferReader 和 bufferWriter

posted on 2016-11-02 21:30  QI XIN  阅读(289)  评论(0编辑  收藏  举报