2

I am trying to compare two txt files using Apache Commons FileUtil tool. Here's my code:

if (entity.isDirectory()){
  File[] listOfFiles = entity.listFiles();   
  for (File file : listOfFiles){
      try {
             if(FileUtils.contentEqualsIgnoreEOL(new File(outputFolder+id+"\\"+file.getName().toString()), 
                                        new File(referenceFolderSolution+file.getName().toString()), null)){
                System.out.println("content equal!!!");
    }

These two files exist in different folders as shown above, but their contents are equal. But still I am not getting the output as content equal!!!.

Any help will be appreciated!

kajarigd
  • 1,261
  • 3
  • 25
  • 41
  • is it possible that some of the characters did not get copied correctly between the files? Some editors add their own characters that you don't know about and won't see. They might add/remove line feed, carriage return, etc. Also, you might be able to use an MD5 hashing algorithm to tell, guava has some hashing methods that could come in handy. If the file is small, you could also use apache's IOUtils to read it to string and then do a string.equals – msknapp Mar 03 '14 at 04:50
  • When I am using FC in command line to compare these two files, I am correctly getting: No difference found. – kajarigd Mar 03 '14 at 05:29
  • are those files big? can you read them entirely into memory to be sure that you are loading the correct thing? Can you put a break point in that method in FileUtils and step through it? What version of commons-io are you using? – msknapp Mar 03 '14 at 13:43

0 Answers0