zoukankan      html  css  js  c++  java
  • java项目中下载文件文件名乱码

    1. String fileName=new String(URLEncoder.encode(fileName,"utf-8"));

        getResponse().addHeader("Content-Disposition","attachment;filename="+fileName);

       或者new String(fileName.getBytes(),"utf-8")

        //都是乱码%E8%B5%84%E5%AE%A1%E6%96%87%E4%BB%B6%E6%A8%A1%E6%9D%BF

    2.使用gbk呢,不管是URLEncoder.encode还是fileName.getBytes()都也是乱码  //如 ____.txt

    3. 使用ISO8859-1呢

    String fileName=new String(URLEncoder.encode(fileName,"ISO8859-1"));

    //乱码 %3F%3F%3F%3F%3F%3F.txt

    只有在

       new String(fileName.getBytes(),"ISO8859-1"); //正确,不发生乱码

    总之一句话,Java下载文件时文件名用new String(fileName.getBytes(),"ISO8859-1"); 转码就对了。

  • 相关阅读:
    hnust Snowman
    hnust 可口可乐大促销
    hnust 聚宝盆
    hnust 搬书
    hnust 神奇的序列
    hnust 懒人多动脑
    hnust CZJ-Superman
    集合Set--BST实现
    快速排序
    位运算符
  • 原文地址:https://www.cnblogs.com/gaofz/p/6750398.html
Copyright © 2011-2022 走看看