adsense


Showing posts with label JAVA EXAMPLES TRAVERSING DIRECTORY. Show all posts
Showing posts with label JAVA EXAMPLES TRAVERSING DIRECTORY. Show all posts

Wednesday, 28 October 2015

JAVA EXAMPLES TRAVERSING DIRECTORY PAGE 117

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES TRAVERSING DIRECTORY





Java Examples - Traversing Directory



Following example demonstratres how to traverse a directory 
with the help of dir.isDirectory() and dir.list() methods of File class.
import java.io.File;

public class Main {
   public static void main(String[] argv) 
   throws Exception {
      System.out.println("The Directory is traversed.");
      visitAllDirsAndFiles(C://Java);
   }
   public static void visitAllDirsAndFiles(File dir) {
      System.out.println(dir);
      if (dir.isDirectory()) {
         String[] children = dir.list();
         for (int i = 0; i < children.length; i++) {
            visitAllDirsAndFiles
            (new File(dir, children[i]));
         }
      }
   }
}       
Result:
The above code sample will produce the following result.
The Directory is traversed.


JAVA EXAMPLES TRAVERSING DIRECTORY PAGE 110

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES TRAVERSING DIRECTORY






Java Examples - Traversing Directory




Following example demonstratres how to traverse a directory
 with the help of dir.isDirectory() and dir.list() methods 
of File class.
import java.io.File;

public class Main {
   public static void main(String[] argv) 
   throws Exception {
      System.out.println("The Directory is traversed.");
      visitAllDirsAndFiles(C://Java);
   }
   public static void visitAllDirsAndFiles(File dir) {
      System.out.println(dir);
      if (dir.isDirectory()) {
         String[] children = dir.list();
         for (int i = 0; i < children.length; i++) {
            visitAllDirsAndFiles
            (new File(dir, children[i]));
         }
      }
   }
}       
Result:
The above code sample will produce the following result.
The Directory is traversed.