Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "左右"
at java.net.URLDecoder.decode
%引起
%会转换成%25
解决方案:
public static String replacer(String str) { String data = str; try { data = data.replaceAll("%(?![0-9a-fA-F]{2})", "%25"); data = data.replaceAll("\+", "%2B"); data = URLDecoder.decode(data, "utf-8"); } catch (Exception e) { e.printStackTrace(); } return data; }