Import Java.io.File;
Import java.io.*;
Gets all the files in a folder.
/*
Printing requirements:
--A.txt
--Io.doc
--$IO. doc
--code
----. metadata
----DAY18
--Video
----01 thread communication. wmv
----02 Daemon Threads and join methods. wmv
----the creation of filed. wmv
----commonly used methods of file. wmv
----Capture 04.wmv
*/
Idea: You can define a method to get a file in a file, recursively call
public class Demo4 {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
File File = new file ("c:\\users\\cdlx2016\\desktop\\ new Course");
System.out.println (File.getname ());
Tree (file,1);
}
public static void tree (File ff,int leve) {
String PRESTT = "";
for (int i = 0;i<leve;i++) {
prestt+= "--";
}
file[] Child = Ff.listfiles ();
for (int i = 0; i<child.length;i++) {
System.out.println (Prestt+child[i].getname ());
Recursive invocation
if (Child[i].isdirectory ()) {
Looking for children's children
Tree (child[i],leve+1);
}
}
}
}
Get all files in Java--(recursive invocation)