import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Main {
public static void main(String[] args) throws Exception {
BASE64Encoder encoder = new BASE64Encoder();
BASE64Decoder decoder = new BASE64Decoder();
String text = "小滴课堂";
byte[] textByte = text.getBytes("UTF-8");
//编码
String encodedText = encoder.encode(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder.decodeBuffer(encodedText),"UTF-8"));
}
}
import java.util.Base64;
public class Main {
public static void main(String[] args) throws Exception {
Base64.Encoder encoder = Base64.getEncoder();
Base64.Decoder decoder = Base64.getDecoder();
String text = "小滴课堂";
byte[] textByte = text.getBytes("UTF-8");
//编码
String encodedText = encoder.encodeToString(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder.decode(encodedText),"UTF-8"));
}
}