参考地址:http://blog.csdn.net/zhou_kapenter/article/details/62890262

要求:JDK1.8+ 使用java原生工具类即可实现

【这里展示字符串转化为byte[]实现的编码和解码  那文件,例如图片文件是怎么实现编码进行存储的呢? 参考:http://www.cnblogs.com/sxdcgaq8080/p/8404404.html


import java.util.Base64;


final
Base64.Decoder decoder = Base64.getDecoder(); final Base64.Encoder encoder = Base64.getEncoder(); final String text = "字串文字"; final byte[] 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"));

 

相关文章:

  • 2021-06-20
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案