校验经过base64编码的字符串是否是图片文件

synchronized private static boolean isImageFromBase64(String base64Str) {
		boolean flag = false;
		try {
			BufferedImage bufImg = ImageIO.read(new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(base64Str)));
			if (null == bufImg) {
				return flag;
			}
			flag = true;
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
		return flag;
	}

base64Str是经过base64编码后的字符串

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