Base64處理byte[ ]和base64字串之間的轉換
阿新 • • 發佈:2019-02-06
1、工具類
2、普通String和byte[]轉換
3、線上轉換工具
http://www.vgot.net/test/image2base64.php?
import org.apache.commons.codec.binary.Base64; public class UtilHelper { //base64字串轉byte[] public static byte[] base64String2ByteFun(String base64Str){ return Base64.decodeBase64(base64Str); } //byte[]轉base64 public static String byte2Base64StringFun(byte[] b){ return Base64.encodeBase64String(b); } }
2、普通String和byte[]轉換
public static void main(String[] args) {
String str="我是中國人";
byte[] arr=str.getBytes();
System.out.println("列印:"+arr);
String str2=new String(arr);
System.out.println("列印2:"+str2);
}
3、線上轉換工具
http://www.vgot.net/test/image2base64.php?