Reputation: 24667
I have a file that has been created on Windows, so it has carriage returns "\r\n".
The file is used in a test, the contents of the file are compared to the contents of a file that is generated during the test. The test passes on Windows because the generated file has the same carriage return.
But the test doesn't pass on Unix/Mac.
It fails because the generated file has linefeeds, ie. only "\n".
Can any one advise how to deal with this?
Edit: The test is a JUnit (Java) test.
Upvotes: 2
Views: 335
Reputation: 24667
I ended up not using a real file, and had the test create the file on the platform at runtime using the system property to get the platforms line terminator.
Upvotes: 0
Reputation: 533880
You can try the following to avoid reading line by line with
String text = FileUtils.readFileAsString(filename)
.replaceAll("(\r\n|\r|\n)", "\n");
This replaces all new-lines of any type with "\n"
Upvotes: 1
Reputation: 4923
Upvotes: 1