使用jdk方法URLEncoder和URLDecoder
package demo;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class URLEncoderAndDecoder {
public static void main(String[] args) {
String temp = "我是李明,今年18岁";
try {
temp = URLEncoder.encode(temp, "utf-8");
System.out.println(temp);
temp = URLDecoder.decode(temp, "utf-8");
System.out.println(temp);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}