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);
        }
    }

以上处理即可。

发布了9 篇原创文章 · 获赞 3 · 访问量 2363

猜你喜欢

转载自blog.csdn.net/qq_35850405/article/details/105217990