Input byte array has incorrect ending byte at 420652

1,962 阅读1分钟

这个问题一般都是转译的问题。或者在写decode的时候写成了file.byte[]。

if (file.contains("data:")) {
    int start = file.indexOf(",");
    file = file.substring(start + 1);
}
final Base64.Decoder decoder = Base64.getDecoder();
file = file.replaceAll("\r|\n", "");
file = file.trim();
byte[] bytes = decoder.decode(file);

这样写基本可以解决这个问题。