title: Comparing two files using commons or Javascript
body: <p>I need to check if any of the 4 uploaded files are same, this check might be on the JSP or Java-Servlet side.</p>
  
  <p>I've been using </p>
  
  <pre><code>var FileName1 = document.getElementById('fileChooser1').value;
  var FileName2 = document.getElementById('fileChooser2').value;
  if(FileName1 == FileName2)
  {
   alert("same files cannot be uploaded");
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>So, on apache commons search I found that there is a <a href="http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/comparator/DefaultFileComparator.html" rel="nofollow">Default Comparator</a> but I have no idea of how I can use this or is there any other better/simpler way to check for same files.</p>
  
  <ol>
  <li>How can I use the <a href="http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/comparator/DefaultFileComparator.html" rel="nofollow">Default Comparator</a> and on what basis does it compare?</li>
  <li>Is there any better/simpler solution to this problem in java or javascript?</li>
  </ol>