public static String base64decode(String text) {

    try {
      return new String(dec.decodeBuffer(text), DEFAULT_ENCODING);
    } catch (IOException e) {
      return null;
    }
  } // base64decode
Example #2
0
  /**
   * 对字节数组字符串进行Base64解码并生成图片
   *
   * @param imgStr 转换为图片的字符串
   * @param imgCreatePath 将64编码生成图片的路径
   * @return
   */
  public static boolean generateImage(String imgStr, String imgCreatePath) {
    if (imgStr == null) // 图像数据为空
    return false;
    BASE64Decoder decoder = new BASE64Decoder();
    try {
      // Base64解码
      byte[] b = decoder.decodeBuffer(imgStr);
      for (int i = 0; i < b.length; ++i) {
        if (b[i] < 0) { // 调整异常数据
          b[i] += 256;
        }
      }

      OutputStream out = new FileOutputStream(imgCreatePath);
      out.write(b);
      out.flush();
      out.close();
      return true;
    } catch (Exception e) {
      return false;
    }
  }