自己在做一個小網站充當練手,但是前端圖片經過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碼粘貼到記事本然后自己在試著解碼,也是同樣問題。
Java Base64解碼錯誤
明月笑刀無情
2019-03-06 18:12:57