java通过流下载文件

response.reset();
response.setContentType("application/octet-stream; charset=UTF-8"); 
response.setHeader("Content-Disposition", "attachment; filename=image");  


InputStream in = null;
try {
 in = new FileInputStream(thubFile);
 OutputStream os = response.getOutputStream();
 byte[] buffer = new byte[1024];
 int len;
 while((len = in.read(buffer)) > 0){
 os.write(buffer, 0, len);
 }
 os.flush();
 in.close();
} catch (FileNotFoundException e) {
 e.printStackTrace();
} catch (IOException e) {
 e.printStackTrace();
}

你可能感兴趣的:(java通过流下载文件)