我是靠谱客的博主 笨笨便当,这篇文章主要介绍Java 字符串Base64编码和解码,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
//编码 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
复制代码
1
2
3
4
//解码 String decode = new String(Base64.getDecoder().decode(encode), StandardCharsets.UTF_8); System.out.println(decode); // 我是码农

最后

以上就是笨笨便当最近收集整理的关于Java 字符串Base64编码和解码的全部内容,更多相关Java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部