Sample Programs

Sample java program to get the directory content


 package org.jusfortechies.example; 

 import java.io.File;
 
 public class DirectoryContent {

   public static void main(String[] args) {
      
      File dir = new File("C:\\SamplePrograms");
		
      // Get a list of files under the specified directory
      File[] files = dir.listFiles();

      // Iterate the list of files in the given directory and print them.
      for (File file : files) {
         System.out.println((file.isDirectory() ? "[Directory] " : "[File] ") + file);
      }

   }

 }




blog comments powered by Disqus