当前位置:网站首页>记录一次换行符引起的bug
记录一次换行符引起的bug
2022-06-27 00:05:00 【华为云】
在学习java以来,一值都把\n当作换行符,偶尔看见有的地方换行符是\r\n,也没有去在意。
但在一次项目中,我需要去向一个接口请求一个证书,然后再把这个证书的字符串,封装首尾,存在一个文件。
证书大概是下面这样。
我请求接口获取的是中间的字符串,而第一行和最后一行是手动添加的。
代码如下:
这个证书是crt格式的,我还需要用openssl把这个crt证书转成p12证书。
结果我执行转换命令的时候,结果如下:
提示找不到证书,后来我把这个证书的内容复制到其他文件,再去执行,居然又能解析了。
想不通为什么,明明两个文件内容一模一样,但是一个证书能解析,一个不行。
后来仔细对比两个证书的内容,发现还是有一点的区别。
一个证书的换行符是占了一个字节,而另一个占了两个字节。
后来查阅资料得知,
回车:Carriage Return 使用转义字符’\r’表示,很显然用的是第2个单词的首字母。
换行:New Line 使用转义字符’\n’表示,很显然用的是第1个单词首字母。
Windows系统里面,每行结尾是“<换行><回车>”,即“\n\r”;如果在一下文件换行使用\n,可能会有意想不到的错误。
代码修改为:
边栏推荐
猜你喜欢

国内外最好的12款项目管理系统优劣势分析

Batch generate folders based on file names

Kubeadm create kubernetes cluster

Competition Registration | one of the key ai+ scientific computing competitions - China open source scientific software creativity competition, competing for 100000 bonus!
![[test] the content of the hottest test development learning route has been updated again to help pass the customs and open the test of large factories](/img/ee/b7cb528b79036896da781b73620758.jpg)
[test] the content of the hottest test development learning route has been updated again to help pass the customs and open the test of large factories

Super hard core! Can the family photo album on Huawei's smart screen be classified automatically and accurately?

【Vscode】预览md文件

万字详解-MindArmour 小白教程!

敲重点!最全大模型训练合集!
![[vscode] setting sync, a plug-in for synchronizing extensions and settings](/img/e0/4889b59105e9815d11ae31988f58f2.jpg)
[vscode] setting sync, a plug-in for synchronizing extensions and settings
随机推荐
Mindspire, a domestic framework, cooperates with Shanshui nature conservation center to find and protect the treasure life in the "China water tower"
【UVM实战 ===> Episode_3 】~ Assertion、Sequence、Property
全網最全的混合精度訓練原理
[microservices] Understanding microservices
Super hard core! Can the family photo album on Huawei's smart screen be classified automatically and accurately?
Can't write to avoid killing and can easily go online CS through defender
Outside the code: writing is the best way to force growth
Reading graph augmentations to learn graph representations (lg2ar)
[微服务]认识微服务
不会写免杀也能轻松过defender上线CS
万字详解-MindArmour 小白教程!
大赛报名 | AI+科学计算重点赛事之一——中国开源科学软件创意大赛,角逐十万奖金!
从位图到布隆过滤器,C#实现
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
kubernetes可视化界面dashboard
利用burp精准定位攻击者
Is it safe to buy pension insurance online? Is there a policy?
【Vscode】预览md文件
“message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“
中信证券佣金 网上开户炒股安全吗