How to read all the files inside the directory in java ?

/*
To Read all the list of files inside the folder using Java code
 */
package basics;
import java.io.File;

/**
 *
 * @Easy Java */
public class ReadFilesFromFolder {
  public static File folder = new File("D:\\Author");
  static String temp = "";

  public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("Reading files under the folder "+ folder.getAbsolutePath());
    listFilesForFolder(folder);
  }

  public static void listFilesForFolder(final File folder) {

    for (final File fileEntry : folder.listFiles()) {
      if (fileEntry.isDirectory()) {
        // System.out.println("Reading files under the folder "+folder.getAbsolutePath());
        listFilesForFolder(fileEntry);
      } else {
        if (fileEntry.isFile()) {
          temp = fileEntry.getName();
          if ((temp.substring(temp.lastIndexOf('.') + 1, temp.length()).toLowerCase()).equals("txt") && (temp.substring(temp.lastIndexOf('.') + 1, temp.length()).toLowerCase()).equals("xls"))
            System.out.println("File= " +fileEntry.getName());
        }

      }
    }
  } 
}





Comments

Popular posts from this blog

How do i Increase the capacity of the Eclipse Output console?

An internal error occurred during: "Building workspace". Java heap space

How to convert the Math Number to Words in Java?