- public void DownloadFileManager(String filename, String url)
- throws IOException {
- HttpServletResponse response = Struts2Utils.getResponse();
- HttpServletRequest request = Struts2Utils.getRequest();
- InputStream is = null;
- OutputStream os = null;
- try {
- String agent = (String)request.getHeader("USER-AGENT");
- if(agent != null && agent.indexOf("MSIE") == -1) {
- String enableFileName = "=?UTF-8?B?" + (new String (Base64.encodeBase64(filename.getBytes("UTF-8")))) + "?=";
- response.setHeader("Content-Disposition", "attachment; filename=" + enableFileName);
- }else {
-
- String enableFileName = new String(filename.getBytes("GBK"), "ISO-8859-1");
- response.setHeader("Content-Disposition", "attachment; filename=" + enableFileName);
- }
-
-
-
-
-
- response.setContentType("application/x-msdownload");
- is = new FileInputStream(url);
- os = response.getOutputStream();
- byte[] buffer = new byte[21940];
- int length = 0;
- while ((length = is.read(buffer)) > 0) {
- os.write(buffer, 0, length);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (os != null) {
- os.close();
- }
- if (is != null) {
- is.close();
- }
- }
-
- }
posted on 2012-07-07 00:40
邦 阅读(854)
评论(0) 编辑 收藏