方法1:
String str = "Hello World"; try{ byte[] encodebase64 = base64.encodebase64(str.getBytes("UTF-8")); System.out.println("Result: " + new String(encodebase64)); } catch(UnsupportedEncodingException e){ e.printStackTrace(); } commons-codec commons-codec 1.12
方法2:
String a = "伦家是一个非常长的字符串"; //5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5Liy String encode = base64.encode(a); // 还原为a String decodeStr = base64.decodeStr(encode); cn.hutool hutool-all 5.3.5
hutool链接



