title: How to delete duplicate files from a particular directory
body: <p>I want to count the no files in which a string is occurring and I have a list of documents in a directory but they are redundant. How do I remove the duplicate files from that particular directory?
  Any help appreciated!</p>
  
  <pre><code> public static boolean CompareFiles(File x, File y) throws FileNotFoundException 
   { //boolean result=true;
  
      try     {
         Scanner xs = new Scanner(x);
         Scanner ys = new Scanner(y);
         boolean result = true;
         while (result)
         {
             if (xs.nextByte() != ys.nextByte()) result = false;
  
  
         }
  
  return result;
      }
  catch (FileNotFoundException e) 
  {
      System.out.println(e.getMessage());
      return false;
  }
  }
  
  public static void main(String[] args) throws FileNotFoundException, IOException//     
      { 
  
      File dir = new File("C:/Users/Aravind/Documents/ranked");
      File[] fileList = dir.listFiles();
      for (int x = 0; x &lt;fileList.length; x++)
      {
      for (int y = x+1; y &lt; fileList.length; y++)
      {
      if (CompareFiles(fileList[x],fileList[y])) 
      {
          System.out.println("in calling fn");
          fileList[x].delete();
      }
          //System.out.println(fileList[x]);
      }
  }
  </code></pre>