ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Base64 字符串中的换行符

Base64 字符串中的换行符

Base64 字符串中的换行符

  1. Base64 编码字符串中不应该包含任何换行符\n或其他空白字符

  2. 一些旧的或特定的 Base64 编码器可能会每 76 个字符插入一个换行符,这是遵循 MIME 标准的行为

  3. MIME Base64 字符串每 76 字符有\r\n,纯净 Base64 字符串无任何换行符

StringimagePath="base64Recourse/output.jpg";try(FileInputStreamfileInputStream=newFileInputStream(imagePath)){byte[]bytes=fileInputStream.readAllBytes();Stringbase64=Base64.getEncoder().encodeToString(bytes);if(base64.contains("\n")){System.out.println("Base64 字符串包含 \\n");}else{System.out.println("Base64 字符串不包含 \\n");}}catch(IOExceptione){e.printStackTrace();}
# 输出结果 Base64 字符串不包含 \n
StringimagePath="base64Recourse/output.jpg";try(FileInputStreamfileInputStream=newFileInputStream(imagePath)){byte[]bytes=fileInputStream.readAllBytes();Stringbase64=Base64.getMimeEncoder().encodeToString(bytes);if(base64.contains("\n")){System.out.println("Base64 字符串包含 \\n");}else{System.out.println("Base64 字符串不包含 \\n");}}catch(IOExceptione){e.printStackTrace();}
# 输出结果 Base64 字符串包含 \n
返回列表