Notice: Undefined index: HTTP_ACCEPT_ENCODING in C:\server\web\www.showyounger.com\s-system.php on line 2
浏览器gzip下载 | 小样儿(ShowYounger)
小样儿,顶呱呱!!![http://www.showyounger.com]
- public static void downloadFile(String filepath, String filename, HttpServletResponse response, PageContext pageContext) {
-
- InputStream inputStream= null;
- OutputStream outputStream = null;
- JspWriter out = pageContext.getOut();
-
- try {
- inputStream = new BufferedInputStream(new FileInputStream(filepath));
-
- String contentType = "application/octet-stream";
-
-
- response.setContentType(contentType);
-
-
- filename = StringUtils.nullToUnknown(filename);
- filename = WebUtils.convertCharset(filename, Constants.ENCODING_GBK, Constants.ENCODING_ISO88591);
- response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
-
- byte[] bytes = new byte[10240];
- int i =0;
- outputStream = response.getOutputStream();
-
- while ((i = inputStream.read(bytes)) > 0) {
- outputStream.write(bytes, 0, i);
- }
- } catch (Exception e) {
-
- } finally {
- WebUtils.closeOutputStream(outputStream);
- WebUtils.closeInputStream(inputStream);
- WebUtils.flushResponse(response);
- WebUtils.outClear(out, pageContext);
- }
- }