集册 Java实例教程 在字节数组和Base64之间转换

在字节数组和Base64之间转换

欢马劈雪     最近更新时间:2020-01-02 10:19:05

500
在字节数组和Base64之间转换
/** 
 来自 时 代 J a v a - nowjava.com**/

import java.io.IOException;


public class Main {


  public void main(String[] argv) {

    try {

      // Convert a byte array to base64 string

      byte[] buf = new byte[] { 0x12, 0x23 };

      String s = new sun.misc.BASE64Encoder().encode(buf);


      // Convert base64 string to a byte array

      buf = new sun.misc.BASE64Decoder().decodeBuffer(s);

    } catch (IOException e) {//时 代 J a v a 公 众 号 提供

    }

  }

}