范例1:
package haizhu.com.InetDemo;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class CodeDemo {
public static void main(String[] args) throws Exception{
String keyWord = "haizhu 海竹";
String encode = URLEncoder.encode(keyWord, "UTF-8");
String decode = URLDecoder.decode(encode, "UTF-8");
System.out.println("编码之后的内容:"+encode);
System.out.println("解码之后的内容:"+decode);
}
}
结果:
编码之后的内容:haizhu+%E6%B5%B7%E7%AB%B9
解码之后的内容:haizhu 海竹