BASE64转码成字符串和字符串转化为bytebuffer
程序员文章站
2022-06-21 20:58:54
...
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;
}
}
}
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;
}
}
}
上一篇: SQLYog中常用的快捷键大全