troubleshooting Question

Java Prog to avoid Duplicate String collection

Avatar of mkhan900
mkhan900 asked on
14 Comments8 Solutions545 ViewsLast Modified:
The program below gives me the path of all the files ending with ".dat"
However, is there a way to avoid duplicates. A file can exists in multiple folders, I need the program to display the file only once and skip all the occurences of the same file.
H:\folder\foldername\filename.dat, if is found again it should be skipped.

public class DatFilePrinter{
   public static void main(String args[]){
    printDatFiles(new File(args[0]));
   public static void printDatFiles(File f){
      f.listFiles(new FileFilter(){
          public boolean accept(File f){
             if (f.isDirectory()) printDatFiles(f);
             else if (f.getName().endsWith(".dat")) System.out.println(f.getName());
             return true;
          }   });   }}
Mick Barry
Java Developer
Join our community to see this answer!
Unlock 8 Answers and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 8 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros