欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

BASE64转码成字符串和字符串转化为bytebuffer

程序员文章站 2022-06-21 20:58:42
...
import sun.misc.BASE64Decoder;
import java.nio.ByteBuffer;
public class Base64Utils {
public static String getFromBASE64(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b, "UTF-8");
} catch (Exception e) {
return null;
}
}
public static ByteBuffer getFromBASE64byte(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {

return decoder.decodeBufferToByteBuffer(s);//decoder.decodeBuffer(s);
} catch (Exception e) {
return null;
}
}
}
相关标签: SUN