1.3 举例
public static void main(String[] args) throws UnsupportedEncodingException {
String str = “编码测试±./&=a=1*%123”;
String charset = “utf-8”;
System.out.println("urlEncoder编码数据: " + str);
String encode = URLEncoder.encode(str, charset);
System.out.println("编码结果: " + encode);
String decode = URLDecoder.decode(encode, charset);
System.out.println("解码结果: " + decode);
}
2.3 举例
public static void main(String[] args) throws UnsupportedEncodingException {
String str = “编码测试±./&=a=1*%123”;
String charset = “utf-8”;
System.out.println("base64编码数据: " + str);
String encode = new String(Base64.getEncoder().encode(str.getBytes()));
System.out.println("编码结果: " + encode);
String decode = new String(Base64.getDecoder().decode(encode));
System.out.println("解码结果: " + decode);
}
Java:URLEncoder、URLDecoder、Base64编码与解码
最新推荐文章于 2024-07-30 15:25:02 发布