Javaå®ç°ç¹å»ä¸è½½æ件çæ¶åï¼å¼¹åºâå¦å为â对è¯æ¡ï¼éæ©ä¿åä½ç½®ï¼ç¶åä¸è½½ï¼ä»£ç å¦ä¸ï¼
public void downLoad(String filePath, HttpServletResponse response)
throws Exception {
System.out.println("filePath"+filePath);
File f = new File(filePath);
if (!f.exists()) {
response.sendError(404, "File not found!");
return;
}
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + f.getName());
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0) out.write(buf, 0, len);
br.close();
out.close();
}