Source Code : Listing the Directory Contents

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Listing the Directory Contents

Listing the Directory Contents
  
import java.io.File;
import java.util.Arrays;

public class Dir {
  static int indentLevel = -1;

  static void listPath(File path) {
    File files[]; 
    indentLevel++; 

    files = path.listFiles();

    Arrays.sort(files);
    for (int i = 0, n = files.length; i < n; i++) {
      for (int indent = 0; indent < indentLevel; indent++) {
        System.out.print("  ");
      }
      System.out.println(files[i].toString());
      if (files[i].isDirectory()) {

        listPath(files[i]);
      }
    }
    indentLevel--; 
  }

  public static void main(String args[]) {
    listPath(new File("c:\"));
  }
}
           
         
    
  

Thank with us