I am trying to read a text file, line-by-line and concatenate the lines to create a single string. But while creating that unified string, 0A
is being added after each line. The string itself is just one line and I cannot see the 0A
in normal text/Java editor, but when I open it in an Hex editor, I can see '0A' after each line. I am working on a Linux (Ubuntu) platform.
I have tried every possible thing to remove them, specifically Java How to remove carriage return (HEX 0A) from String?
But I am not able to remove them. Any thoughts about how to do this?
UPDATE:
File workingFolderLocal = new File("src/test/resources/testdata");
String expected = "String1";
MyClass myClass = new MyClass();
myClass.createPopFile(workingFolderLocal);
// Read the created file and compare with expected output
FileInputStream fin = new FileInputStream(workingFolderLocal + "/output.xyz");
BufferedReader myInput = new BufferedReader(new InputStreamReader(fin));
StringBuilder actual = new StringBuilder("");
String temp = "";
while ((temp = myInput.readLine()) != null) {
String newTemp = temp.replaceAll("\r", "");
actual.append(newTemp);
}
System.out.println("actual: " + actual.toString());
myInput.close();
Assert.assertEquals(expected, actual);
Here is the output/error I am getting:
actual: String1
FAILED: testCreatPopFile
junit.framework.AssertionFailedError: expected:<String1> but was:<String1>
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.failNotEquals(Assert.java:277)
at junit.framework.Assert.assertEquals(Assert.java:64)
at junit.framework.Assert.assertEquals(Assert.java:71)