public static void main(String[] args) throws UnsupportedEncodingException {
String name="中文";
//URL编码
String nameStr=new String(java.net.URLEncoder.encode(name,"utf-8").getBytes());
System.out.println(nameStr);
String cnStr = "中文";
String cnStr1 = "";
cnStr1 = new String(java.net.URLEncoder.encode(cnStr, "UTF-8").getBytes(), "ISO-8859-1");
System.out.println(cnStr1);
//URL解码
System.out.println(java.net.URLDecoder.decode(new String(cnStr1.getBytes("ISO-8859-1"), "UTF-8"), "UTF-8"));
}
转载于:https://my.oschina.net/u/2480757/blog/661602