public class RecursiveReader { /* * Constructor for RecursiveReader */ public RecursiveReader(){ // get handler to current directory File currDir = new File(System.getProperty("user.dir"));
this.recursiveDirReader(currDir); } //-- ends class constructor
private void recursiveDirReader(final File handler) { if (handler.isDirectory()){ File [] files = handler.listFiles(); System.out.println("Now Reading: "+ handler.getAbsolutePath()); for(File f : files) { if (f.isFile()){ // do something with the file. System.out.println("File: '" + f.getName()); } //-- end if block else if(f.isDirectory()){ // if directory...call the method for recursion System.out.println("Now Reading: "+ f.getAbsolutePath()); recursiveDirReader(f); } //-- ends else if block } //-- ends foreach block } //-- end if block } //-- ends
public static void main(String[] args) { new RecursiveReader(); } //-- ends class method main