Base64 字符串中的换行符
Base64 字符串中的换行符Base64 编码字符串中不应该包含任何换行符\n或其他空白字符一些旧的或特定的 Base64 编码器可能会每 76 个字符插入一个换行符这是遵循 MIME 标准的行为MIME Base64 字符串每 76 字符有\r\n纯净 Base64 字符串无任何换行符StringimagePathbase64Recourse/output.jpg;try(FileInputStreamfileInputStreamnewFileInputStream(imagePath)){byte[]bytesfileInputStream.readAllBytes();Stringbase64Base64.getEncoder().encodeToString(bytes);if(base64.contains(\n)){System.out.println(Base64 字符串包含 \\n);}else{System.out.println(Base64 字符串不包含 \\n);}}catch(IOExceptione){e.printStackTrace();}# 输出结果 Base64 字符串不包含 \nStringimagePathbase64Recourse/output.jpg;try(FileInputStreamfileInputStreamnewFileInputStream(imagePath)){byte[]bytesfileInputStream.readAllBytes();Stringbase64Base64.getMimeEncoder().encodeToString(bytes);if(base64.contains(\n)){System.out.println(Base64 字符串包含 \\n);}else{System.out.println(Base64 字符串不包含 \\n);}}catch(IOExceptione){e.printStackTrace();}# 输出结果 Base64 字符串包含 \n