public void publicDownFileCommon(HttpServletResponse response,
HttpServletRequest request, String fullPath, String orgName)
throws IOException {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
request.setCharacterEncoding("UTF-8");
// String filePath = fullPath + File.separator + orgName;
// response.setContentType("application/x-msdownload;");
// response.setHeader("Content-disposition", "attachment; filename="
// + orgName);
response.reset();
response.setContentType("application/octet-stream;charset=UTF-8");
response.addHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(orgName, "UTF-8"));
bis = new BufferedInputStream(new FileInputStream(fullPath));
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);
}
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
文件下载
最新推荐文章于 2024-09-01 15:30:33 发布