public static ArrayList<File> listAllFiles(File folder){
  ArrayList<File> list=new ArrayList<File>();
  if (!folder.exists() || folder.listFiles() == null || folder.listFiles().length <= 0 || !folder.canRead()) {
    return list;
  }
  File[] listf=folder.listFiles();
  for (  File f : listf) {
    if (f.isFile()) {
      list.add(f);
    }
 else {
      if (listAllFiles(f) != null)       for (      File f1 : listAllFiles(f)) {
        list.add(f1);
      }
    }
  }
  return list;
}

public static ArrayList < File > listAllFiles ( File folder ) { ArrayList < File > list = new ArrayList < File > ( ) ; if ( ! folder . exists ( ) || folder . listFiles ( ) == null || folder . listFiles ( ) . length <= 0 || ! folder . canRead ( ) ) { return list ; } File [ ] listf = folder . listFiles ( ) ; for ( File f : listf ) { if ( f . isFile ( ) ) { list . add ( f ) ; } else { if ( listAllFiles ( f ) != null ) for ( File f1 : listAllFiles ( f ) ) { list . add ( f1 ) ; } } } return list ; }
lists all files in a given folder
