title: How to delete Duplicate files in folder using Java-Stream?
body: <p>I have a folder with the same photos but having different names and I want to remove the duplicates (doesn't matter which ones) using Stream API, to which I'm fairly new.</p>
  <p>I tried to use this method, but of course it's not that simple, and it's just deleting all files.</p>
  <pre><code>File directory = new File(&quot;D:\\Photos\\Test&quot;);
  
  List&lt;File&gt; files = Arrays.asList(Objects.requireNonNull(directory.listFiles()));
  files.stream().distinct().forEach(file -&gt; Files.delete(file.toPath()));
  </code></pre>
  <p>I also tried to convert each file into a byte array and apply <code>distinct()</code> on the stream of byte arrays, but it didn't find any duplicates.</p>
  <p>Is there a way to make this happen by using only stream?</p>