IT Certificaions

Google Cloud Platform

Monday, September 5, 2011

List all files in a directory using java

=======List all file with their names in a existing directory  on your hard disk=====
        String walkImageDir="C://MyDirectory//imageFiles";
         File dir = new File(imageDir);
         System.out.println("===dir.isDirectory()====="+dir.isDirectory());
          
           if(dir.isDirectory()){
                File[] imgFiles = dir.listFiles();
                System.out.println("===file dir size:"+imgFiles.length);
                for(File image: imgFiles){
                     System.out.println("====images are :"+image.getName());
                   
                }
              }