jsp下载文件

File file=new File(directory);
String fileName=new String(file.getName().getBytes("utf-8"),"ISO-8859-1");
response.setContentType("application/x-download");//设置为下载application/x-download
response.addHeader("Content-Disposition", "attachment;filename="
+ fileName);
InputStream is = null;
OutputStream os = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;

is = new FileInputStream(file);
bis = new BufferedInputStream(is);
os = response.getOutputStream();
bos = new BufferedOutputStream(os);

byte[] b = new byte[1024];
int len = 0;
while((len = bis.read(b)) != -1){
bos.write(b,0,len);
}

bis.close();
is.close();
bos.close();
os.close();

原文出处:/show_1EF3fTCd6K2.html