Java-response-文件流下载文件中文名称丢失或者乱码问题,针对IE

 

/**
    public void copyReponseFile(OutputStream out, BufferedInputStream bis, BufferedOutputStream bos,
            Map paths, HttpServletResponse response, Map 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);
        }
    }

以上处理即可。

你可能感兴趣的:(乱码)