Java 8的java.util套件中,新增了Base64的类别,可以用来处理Base64的编码与解码,用法如下
final Base64.Decoder decoder = Base64.getDecoder();
final Base64.Encoder encoder = Base64.getEncoder();
try {
final String text = "字串文字";
byte[] textByte;
textByte = text.getBytes("UTF-8");
//编码
final String encodedText = encoder.encodeToString(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder.decode(encodedText), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
原文:https://www.cnblogs.com/anenyang/p/12112583.html