PackageCom.yyq;ImportJava.io.*;/** List the files or folders under the specified directory, including the contents under subdirectories * that is, list all content in the specified directory*/ Public classFileDemo3 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubFile dir =NewFile ("E:\\java Video learning \\java basic Video"); Showdir (dir); } //recursive invocation: Because there are directories in the directory, just use a function that lists the directory functions to//itself calls itself Public Static voidShowdir (File dir) {System.out.println (dir); file[] Files=Dir.listfiles (); for(File f:files) {if(F.isdirectory ()) {showdir (f); } Else{System.out.println (f); } } }}
Package com.yyq;
Import java.io.*;
/*
* List the files or folders under the specified directory, including the contents of the sub-directory
* That is, list all content in the specified directory
*/
public class FileDemo3 {
public static void Main (string[] args) {
TODO auto-generated Method Stub
File dir = new file ("E:\\java Video learning \\java basic video");
Showdir (dir);
}
Recursive invocation: Because there are directories in the directory, just use a function that lists the directory functions to
itself calls itself
public static void Showdir (File dir) {
System.out.println (dir);
file[] files = dir.listfiles ();
for (File f:files) {
if (F.isdirectory ()) {
Showdir (f);
}
else{
System.out.println (f);
}
}
}
}
Io Stream lists all contents under directory-recursion