PackageCom.xiwi;ImportJava.io.*;ImportJava.util.*;classfile{ Public Static voidMain (String args[]) {System.out.println ("File Go ..."); //change this to the directory path you want to traverse.Recursivefiles ("F:\\filetext"); System.out.println ("File End."); } /*** Xiwi * Traverse files/Folders-functions * [String]path file path*/ Private Static voidrecursivefiles (String path) {//Create a File objectFile File =NewFile (path); //fetch files/foldersFile files[] =File.listfiles (); //object is empty direct return if(Files = =NULL){ return; } //file under directory if(Files.length = = 0) {System.out.println (path+ "No files under this folder"); } //existence of file traversal judgment for(File f:files) {//determine if a folder if(F.isdirectory ()) {System.out.print ("Folder:"); System.out.println (F.getabsolutepath ()); //continue traversal for a folderRecursivefiles (F.getabsolutepath ()); //determine if the file is}Else if(F.isfile ()) {System.out.print ("File:"); System.out.println (F.getabsolutepath ()); } Else{System.out.print ("Unknown error file"); } } } }
[Java] File class recursively gets all files/folders under directory