public class obscureStr { public static void main(String[] args) { String a = "你好 % 18.0000"; String b; try { b = URLDecoder.decode(a, "UTF-8"); System.out.println(b); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
出错:
Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " 1" at java.net.URLDecoder.decode(Unknown Source) at obscureStr.main(obscureStr.java:9)
请问为什么呢?
------解决方案--------------------
Java code
String a = "你好 % 18.0000";
String b;
try
{
b = URLEncoder.encode(a, "UTF-8");
System.out.println(b);
a = URLDecoder.decode(b, "UTF-8");
System.out.println(a);
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
------解决方案--------------------