java 含有%文字 decode 异常 处理 java
程序员文章站
2024-02-12 08:27:28
...
含有百分号文字如:
欧洲7月电动车销量跌4% 高尔夫GTE最惨
decode时会抛出异常
解决方法 : 将%替换为 %25
参考资料:
http://*.com/questions/6067673/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string
欧洲7月电动车销量跌4% 高尔夫GTE最惨
docName = URLDecoder.decode(docName, "utf-8");
decode时会抛出异常
IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern
解决方法 : 将%替换为 %25
docUrl = docUrl.replaceAll("%(?![0-9a-fA-F]{2})", "%25"); docName = docName.replaceAll("%(?![0-9a-fA-F]{2})", "%25"); content = content.replaceAll("%(?![0-9a-fA-F]{2})", "%25"); docUrl = URLDecoder.decode(docUrl, "utf-8"); docName = URLDecoder.decode(docName, "utf-8"); content = URLDecoder.decode(content, "utf-8");
参考资料:
http://*.com/questions/6067673/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string