在Base64编码中删除换行符是否可以

2022-01-21 00:00:00 base64 java

我的 java 应用程序使用 base64 编码,它在每 76 个字符后放置一个新行 ( ).我需要将此编码字符串放在属性文件中,换行符会破坏功能.

My java application use base64 encoding which puts a new line ( ) after every 76 character. I need to put this encoded string in a properties file and the newline breaks the functionality.

当我执行 encodedString.replaceAll(" ", ""); 时,一切正常,但我只是想确保这是预期的,我没有引入隐藏问题.

When I do a encodedString.replaceAll(" ", ""); things are working fine, but I just want to make sure that this is expected and I am not introducing a hidden issue.

推荐答案

对于许多无法处理长行的旧程序来说,必须将 base64 编码的字符串分成多行.用 Java 编写的程序通常可以处理长行,因为它们不需要自己进行内存管理.只要您的行少于 6400 万个字符,就应该没有问题.

Breaking a base64 encoded string into multiple lines has been necessary for many old programs that couldn't handle long lines. Programs written in Java can usually handle long lines since they don't need to do the memory management themselves. As long as your lines are shorter than 64 million characters there should be no problem.

而且由于您不需要换行符,因此如果可能的话,您根本不应该生成它们.

And since you don't need the newlines, you shouldn't generate them at all, if possible.

相关文章