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?
有帮助吗?

解决方案

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

Example

System.out.println(FileUtils.contentEquals(file1, file2));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top