将字节数组转换为base64字符串 [英] Convert byte array to base64 string
本文介绍了将字节数组转换为base64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问有人知道如何在Java中将字节数组转换为以64为基数的字符串,以及从基数64字符串转换为以字节数为字节的数组.Java
Hi,
Please does anyone know how I can convert a byte array to base 64 string and from a base 64 string to a byte array in Java
推荐答案
Google知道全部("java字节数组到base64).认真的家伙,我花了整整20秒的时间使用google找到了它:
Google knows all ("java byte array to base64"). Seriously dude, it took me all of 20 seconds to find this using google:
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) {
}
编辑===============
为什么要将此标记为答案,然后取消标记呢?
再次编辑==============
您是否在搜寻如何从base64字符串返回字节数组时遇到麻烦?我发现了一个页面,其中包含两种代码:
http://www.rgagnon.com/javadetails/java-0598.html [ ^ ]
EDIT ===============
Why did you mark this as the answer, and then un-mark it?
EDIT AGAIN ==============
Did you have trouble googling how to go back to a byte array from a base64 string? I found a page that has code for going both ways:
http://www.rgagnon.com/javadetails/java-0598.html[^]
这篇关于将字节数组转换为base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文