response.setHeader("Content-Disposition", "attachment; filename=" + yourFileName);
response.setHeader("Connection", "close");
response.setHeader("Content-Type", "application/octet-stream"); 
response.setContentLength(yourFileSize);
然后就可以用out.write()直接将内容写入到指定文件中,如
out.write(new String(byteBuffer,0,iBufferLength,"ISO-8859-1"));