base64Encode对图片进行编码

/**
	 * 对图片进行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 {
			try {
				if (in != null) {
					in.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return resultStr;
	}

 

你可能感兴趣的:(base64,图片,encoder)