- Base64 已加入到Java8官方库中,且支持 URL 和 MINE 编码解码:
- Base64.getUrlEncoder()
- Base64.getUrlDecoder()
- Base64.getMimeEncoder()
- Base64.getMimeDecoder()
public class Base64s {
public static void main(String[] args) {
final String text = "Base64 finally in Java 8!";
final String encoded = Base64
.getEncoder()
.encodeToString( text.getBytes( StandardCharsets.UTF_8 ) );
System.out.println( encoded );
final String decoded = new String(
Base64.getDecoder().decode( encoded ),
StandardCharsets.UTF_8 );
System.out.println( decoded );
}
}
网友评论