原创

base64Encode对图片进行编码

温馨提示:
本文最后更新于 2016年11月19日,已超过 2,713 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我
/** 
 * 对图片进行base64encoder编码 
 *  
 * @author mrZhang 
 * @param path 
 * @return 
 */  
public static String encodeImage(String path) {  
	BASE64Encoder encoder = null;  
	byte[] b = null;  
	InputStream in = null;  
	String resultStr = null;  
	try {  
		in = new FileInputStream(path);  
		b = new byte[in.available()];  
		in.read(b);  
		// 对字节数组Base64编码  
		encoder = new BASE64Encoder();  
		resultStr = encoder.encode(b);// Base64编码过的字节数组字符串  
	} catch (IOException e) {  
		e.printStackTrace();  
	} finally {  
		if (in != null) {  
			try { 
				in.close(); 
			} catch (IOException e) {  
				e.printStackTrace();  
			} 
		} 			
	}  
	return resultStr;  
} 


正文到此结束
本文目录