File using a recursive method, traversing the output end .java

cn.itcast.demo01 Package ; 

Import java.io.File ;

/ **
* @author newcityman
* @date 2019/7/27 - 19:17
* Topics requirements: traversing the file folder, and the print output file .java end of the file
* /
public class DemoRecurision {
public static void main (String [] args) {
file file = new new file ( "H: \\ Li phase V") ; getAllFile (file) ; } / * define a method, file catalog parameter transfer type process to traverse the directory * / public static void getAllFile (file the dir) { // print traversed folder // System.out.println (the dir); // dir.listFiles () returns all files and directories under the directory dir









File [] = F dir.listFiles () ;
// iterate f, if the directory array f, then the method continues using a recursive traversal for (File File: F) { IF (file.isDirectory ()) { getAllFile (File) ; } the else { IF (file.getPath () the toLowerCase () endsWith (.. ".java")) { the System. Out.println (file) ; // if the file print output file } } } } }











Guess you like

Origin www.cnblogs.com/newcityboy/p/11256500.html