Return to Snippet

Revision: 37226
at December 6, 2010 16:12 by hariharank12


Initial Code
import java.io.File;

public class DirectoryReader {

  public static void main(String[] args) {

    File folder = new File("c:/");
    File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {
      if (listOfFiles[i].isFile()) {
        System.out.println("File " + listOfFiles[i].getName());
      } else if (listOfFiles[i].isDirectory()) {
        System.out.println("Directory " + listOfFiles[i].getName());
      }
    }
  }

}

Initial URL

                                

Initial Description

                                

Initial Title
List of files and directories inside a directory in Java

Initial Tags
java, files

Initial Language
Java