[java]代码库public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String path = this.getServletContext().getRealPath(
"/WEB-INF/huoju-client.zip");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
try {
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename="
+ "huoju-client.zip");
fis = new FileInputStream(path);
bis = new BufferedInputStream(fis);
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
int bytesRead = 0;
byte[] buffer = new byte[5 * 1024];
while ((bytesRead = bis.read(buffer)) != -1) {
bos.write(buffer, 0, bytesRead);// 将文件发送到客户端
}
bos.close();
bis.close();
fos.close();
fis.close();
} catch (IOException e) {
response.reset();
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
if (bos != null) {
bos.close();
}
if (fis != null) {
fis.close();
}
if (bis != null) {
bis.close();
}
} catch (IOException e) {
System.err.print(e);
}
}