您的位置 首页 java

Java 字符串Base64编码和解码

编码

 String message = "我是 码农 ";
String encode = Base64.getEncoder().encodeToString(message.getBytes(StandardCharsets.UTF_8));  // 方式一
String encode2 = new String(Base64.getEncoder().encode(message.getBytes()), StandardCharsets.UTF_8);  // 方式二
System.out.println(encode);  // 5oiR5piv56CB5Yac
System.out.println(encode2);  // 5oiR5piv56CB5Yac  

解码

 String  decode  = new String(Base64.getDecoder().decode(encode), StandardCharsets.UTF_8);
System.out.println(decode);  // 我是码农   

如果您有什么好的想法与方法,欢迎在评论区留言,我们一起讨论~

文章来源:智云一二三科技

文章标题:Java 字符串Base64编码和解码

文章地址:https://www.zhihuclub.com/188450.shtml

关于作者: 智云科技

热门文章

网站地图