Java-response-文件流下載文件中文名稱丟失或者亂碼問題,針對IE

 

/**
    public void copyReponseFile(OutputStream out, BufferedInputStream bis, BufferedOutputStream bos,
            Map<String, String> paths, HttpServletResponse response, Map<String, String> map) throws IOException {
        String projectName = map.get("name");
        out = response.getOutputStream();
        response.reset();
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(projectName, "UTF-8") + "_" + DateUtil.getNowDate("yyyy-MM-dd") + ".zip");
        response.setContentType("application/octet-stream;charset=UTF-8");
        bis = new BufferedInputStream(new FileInputStream(paths.get("filePath")));
        bos = new BufferedOutputStream(out);
        byte[] buff = new byte[1024];
        int bytesRead;
        while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
            bos.write(buff, 0, bytesRead);
        }
    }

以上處理即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章