为了账号安全,请及时绑定邮箱和手机立即绑定

Java Base64解码错误

Java Base64解码错误

明月笑刀无情 2019-03-06 18:12:57
自己在做一个小网站充当练手,但是前端图片经过base64加密后传往后端在解码。但是一直都有问题,请大神赐教    public static String base64ToImg(String src) throws IOException {        String uuid = UUID.randomUUID().toString();        StringBuilder newPath = new StringBuilder(IMG_ROOT_PATH);        newPath.append(separator).                append(uuid).                append(IMG_SUFFIX);        if(src == null){            return null;        }        byte[] data = null;        Base64.Decoder decoder = Base64.getDecoder();        try (OutputStream out = new FileOutputStream(newPath.toString())) {            data = decoder.decode(src);            out.write(data);            return newPath.toString();        } catch (IOException e) {            throw new IOException();        }    }java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit以上是相关的异常信息。我试图将前端的base64码粘贴到记事本然后自己在试着解码,也是同样问题。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 2069 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号