package test; import java.net.URLDecoder; import java.net.URLEncoder; public class Ceshi { public static void main(String[] args) { doc(); } public static void doc() { try { String str = "juapk.com?userName=轻描@淡写.%*"; String strEncode = URLEncoder.encode(str, "UTF-8"); String strDecode = URLDecoder.decode(strEncode, "UTF-8"); System.out.println("原始字符串:" + str); System.out.println("URLEncoder.encode加密:" + strEncode); System.out.println("URLDecoder.decode解密:" + strDecode); } catch (Exception e) { e.printStackTrace(); } } }