下载文件中文乱码问题+路径斜杠问题

(1)路径斜杠问题:

vulnFile.setPath(map.get("path").toString().replace("\\", "\\\\"));

(2)文件名称中文乱码问题:

  1. String code = EncodingUtil.getEncoding(name);
       try {
        String names = new String(name.getBytes(code),"ISO8859-1");
        this.fileName = names.toString();
       } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
       }


  2.  public static  String getEncoding(String str) { 
            String encode = "GB2312"; 
            try { 
                if (str.equals(new String(str.getBytes(encode), encode))) { 
                    String s = encode; 
                    return s; 
                } 
            } catch (Exception exception) { 
            } 
            encode = "ISO-8859-1"; 
            try { 
                if (str.equals(new String(str.getBytes(encode), encode))) { 
                    String s1 = encode; 
                    return s1; 
                } 
            } catch (Exception exception1) { 
            } 
            encode = "UTF-8"; 
            try { 
                if (str.equals(new String(str.getBytes(encode), encode))) { 
                    String s2 = encode; 
                    return s2; 
                } 
            } catch (Exception exception2) { 
            } 
            encode = "GBK"; 
            try { 
                if (str.equals(new String(str.getBytes(encode), encode))) { 
                    String s3 = encode; 
                    return s3; 
                } 
            } catch (Exception exception3) { 
            } 
            return ""; 
        }

你可能感兴趣的:(下载文件中文乱码问题+路径斜杠问题)