将byte数组转化为string,及其还原。

时间:2025-04-14 20:28:47

import ;

import ;

import ;

import .BASE64Decoder;

import .BASE64Encoder;

 

publicclass test2 {

    publicstatic void main(String[] args) {

      

       byte[]before=newbyte[] {80, 75, 3, 4, 10, 60, 82, -83, 68, 8, 0, 28, 0, 80, 97, 121, 108, 108};

      

       BASE64Encoder enc=new BASE64Encoder();

       String mes=enc.encodeBuffer(before); //使用BASE64编码

      

       BASE64Decoder dec=new BASE64Decoder();

       byte[]after=null;

       try {

           after =(mes);//使用BASE64解码

       } catch (IOExceptione) {

           // TODO Auto-generated catch block

           ();

      

      

       System.out.println("before= "+Arrays.toString(before));

       System.out.println("after = "+Arrays.toString(after));

    }

}