为什么fileToString没有正确读取文件的内容?

时间:2020-12-01 15:44:40

I was following the instructions for CLAVIN installation. When I tried to build the CLAVIN package, it would display a 'Build Failure' after the TextUtilsTest, which checks that the contents extracted from a file are exactly the same as an expected String. Here's the code of the TEST, and here's the method that reads contents from file. These are the details behind its failure:

我按照CLAVIN安装的说明进行操作。当我尝试构建CLAVIN包时,它会在TextUtilsTest之后显示“Build Failure”,它会检查从文件中提取的内容是否与预期的String完全相同。这是TEST的代码,这是从文件中读取内容的方法。这些是失败背后的细节:

<failure message="wrong output from fileToString expected:&lt;Line1 word2[&#10;Line2 word2 word3]&#10;Line3&gt; but was:&lt;Line1 word2[&#10;Line2 word2 word3&#13;]&#10;Line3&gt;" type="org.junit.ComparisonFailure"><![CDATA[org.junit.ComparisonFailure: wrong output from fileToString expected:<Line1 word2[
Line2 word2 word3]
Line3> but was:<Line1 word2[
Line2 word2 word3
]
Line3>
    at org.junit.Assert.assertEquals(Assert.java:115)
    at com.bericotech.clavin.util.TextUtilsTest.testFileToString(TextUtilsTest.java:56)
]]></failure>

I checked the input file, and the contents are exactly the same as the provided string. I suspected that the problem is due to the encoding of the text file, I tried all other encodes, but it only made things worst. Would you suggest I ignore the exception, and move on to the next installation step?

我检查了输入文件,其内容与提供的字符串完全相同。我怀疑问题是由于文本文件的编码,我尝试了所有其他编码,但它只是使事情变得最糟糕。您是否建议我忽略该异常,然后继续下一个安装步骤?

1 个解决方案

#1


There is an unexpected &#13; or CR, carriage return, \r. For the rest &#10; or LF, \n is used as newline. Now Windows uses \r\n as newline char, so maybe there is some mess of handing newlines. As a text area on Windows yielding a CR+LF containing text, where LFs were removed, and then pasted into a LF-only XML.

出人意料  或CR,回车,\ r。对于其余的  或LF,\ n用作换行符。现在Windows使用\ r \ n作为换行符,因此可能会有一些处理新行的混乱。作为Windows上的文本区域,产生包含文本的CR + LF,其中LF被删除,然后粘贴到仅LF的XML中。

(The &#13; being a numeric entity for XML. Old MacOS had \r as newline.)

(该  是XML的数字实体。老MacOS \ r \ n作为换行符。)

The solution is some line-ending replace of multi-line input text of merely \n.

解决方案是一些行结束替换只有\ n的多行输入文本。

#1


There is an unexpected &#13; or CR, carriage return, \r. For the rest &#10; or LF, \n is used as newline. Now Windows uses \r\n as newline char, so maybe there is some mess of handing newlines. As a text area on Windows yielding a CR+LF containing text, where LFs were removed, and then pasted into a LF-only XML.

出人意料  或CR,回车,\ r。对于其余的  或LF,\ n用作换行符。现在Windows使用\ r \ n作为换行符,因此可能会有一些处理新行的混乱。作为Windows上的文本区域,产生包含文本的CR + LF,其中LF被删除,然后粘贴到仅LF的XML中。

(The &#13; being a numeric entity for XML. Old MacOS had \r as newline.)

(该  是XML的数字实体。老MacOS \ r \ n作为换行符。)

The solution is some line-ending replace of multi-line input text of merely \n.

解决方案是一些行结束替换只有\ n的多行输入文本。