---
title: "BASE64转码成字符串和字符串转化为bytebuffer"
author: "tomhat"
date: "2010-12-16T16:10:51Z"
tags: []
categories: ["编程语言"]
slug: "base64-bytebuffer"
draft: false
lastmod: "2010-12-30T00:17:11Z"
id: 844718
url: "https://tomhat.iteye.com/blog/844718"
---

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;
		}
	}
}