文件下载文件名乱码

Posted 八稚女

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件下载文件名乱码相关的知识,希望对你有一定的参考价值。

public static String getDownloadFileName(HttpServletRequest request,
            String fileName) {
        String agent = request.getHeader("User-Agent").toUpperCase();
        try {
            if (agent.indexOf("MSIE") > 0 || agent.indexOf("TRIDENT") > 0 || agent.indexOf("EDGE") > 0) {
                fileName = URLEncoder.encode(fileName, "UTF-8");
                fileName = fileName.replaceAll("\\+", "%20");
            } else {
                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return fileName;
    }

 

以上是关于文件下载文件名乱码的主要内容,如果未能解决你的问题,请参考以下文章