1

I need to check if any of the 4 uploaded files are same, this check might be on the JSP or Java-Servlet side.

I've been using

var FileName1 = document.getElementById('fileChooser1').value;
var FileName2 = document.getElementById('fileChooser2').value;
if(FileName1 == FileName2)
{
 alert("same files cannot be uploaded");
}

But, the problem is that this only deals with the name of the file and this fails if files with same content but different names are uploaded.

So, on apache commons search I found that there is a Default Comparator but I have no idea of how I can use this or is there any other better/simpler way to check for same files.

  1. How can I use the Default Comparator and on what basis does it compare?
  2. Is there any better/simpler solution to this problem in java or javascript?
2
  • Looks like you want to compare files in Javascript while Apache commons will give Java based solution Commented Mar 12, 2014 at 11:53
  • It may be either a javascript or java solution, I just want to compare two files and identify duplicate uploads. Commented Mar 12, 2014 at 11:54

1 Answer 1

4

You can use FileUtils.contentEquals method to compare content of 2 files.

Example

System.out.println(FileUtils.contentEquals(file1, file2));
Sign up to request clarification or add additional context in comments.

1 Comment

i think you should go with this solution .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.