Get all files in Java--(recursive invocation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.