String fileName="";
String filePath = "d://max//";//下载文件目录,可以在配置文件中读取
if (request.getParameter("file") != null) {
fileName = request.getParameter("file");
}
response.reset();
response.setHeader("Content-disposition","attachment; filename="+fileName);
// response.setContentType("application/ms-excel");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
System.out.println("Ready to transform file:"+filePath+fileName);
bis = new BufferedInputStream(new FileInputStream(filePath + fileName));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
System.out.println("Each time read content :"+buff.toString());
}
System.out.println("End of transform the file :"+fileName);
} catch(final IOException e) {
System.out.println ( "IOException." + e );
} finally { if (bis != null) bis.close(); if (bos != null) bos.close(); }%>