1 32 33 package com.jeantessier.classreader; 34 35 import java.io.*; 36 import java.util.*; 37 38 public class DirectoryExplorer { 39 private Collection collection = new LinkedList(); 40 41 public DirectoryExplorer(String [] filenames) throws IOException { 42 for (int i=0; i<filenames.length; i++) { 43 explore(new File(filenames[i])); 44 } 45 } 46 47 public DirectoryExplorer(Collection filenames) throws IOException { 48 Iterator i = filenames.iterator(); 49 while (i.hasNext()) { 50 explore(new File(i.next().toString())); 51 } 52 } 53 54 public DirectoryExplorer(String filename) throws IOException { 55 this(new File(filename)); 56 } 57 58 public DirectoryExplorer(File file) throws IOException { 59 explore(file); 60 } 61 62 private void explore(File file) throws IOException { 63 if (file.exists()) { 64 collection.add(file); 65 66 if (file.isDirectory()) { 67 exploreDirectory(file); 68 } 69 } 70 } 71 72 private void exploreDirectory(File dir) throws IOException { 73 String [] entries = dir.list(); 74 for (int i=0; i<entries.length; i++) { 75 explore(new File(dir, entries[i])); 76 } 77 } 78 79 public Collection getCollection() { 80 return collection; 81 } 82 } 83 | Popular Tags |