try {
File f = new File("//路径");
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f), 2 * 1024);
byte[] buf = new byte[1024];
int len = 0;
httpServletResponse.reset(); // 非常重要
httpServletResponse.setContentType("application/x-msdownload");
String fileName = new String("文件名".getBytes(), "ISO-8859-1");
httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + fileName);
OutputStream out = httpServletResponse.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
File f = new File("//路径");
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f), 2 * 1024);
byte[] buf = new byte[1024];
int len = 0;
httpServletResponse.reset(); // 非常重要
httpServletResponse.setContentType("application/x-msdownload");
String fileName = new String("文件名".getBytes(), "ISO-8859-1");
httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + fileName);
OutputStream out = httpServletResponse.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}