Package Com.readfile;import Java.io.file;public class Getallfiles {public static void main (string[] args) {//path Here write a path into string path= "F:\\QQ document";//Call Method GetFiles (path);} /** * Recursively gets all files, folders under a path, and outputs */public static void GetFiles (String path) {File File = new file (path);//If the path is a folder if (file.i Sdirectory ()) {//Get all Files under path file[] files = file.listfiles (); for (int i = 0; i < files.length; i++) {//If the folder recursively gets the text inside Folder if (Files[i].isdirectory ()) {System.out.println ("directory:" + Files[i].getpath ()); GetFiles (Files[i].getpath ());} else {System.out.println ("file:" + Files[i].getpath ());}}} else {System.out.println ("file:" + File.getpath ());}}}
Java recursion gets all the files under a path, folder names