In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "java how to use File class application traversal folder all files", in daily operation, I believe many people in java how to use File class application traversal folder all files on the problem there are doubts, small make up all kinds of information, sort out simple and easy to use operation method, hope to answer "java how to use File class application traversal folder all files" doubts helpful! Next, please follow the small series to learn together!
Code:
package Travels all files in a folder;import java.io.File;public class Test { public static void main(String[] args){ File file=new File("D:\\tcb\\Week Summary"); filesDirs(file); } //Travels files in folders and subfolders using recursion public static void filesDirs(File file){ //File object is the path to a file or folder, the first level determines whether the path is empty if(file!= null){ //The second layer path is not empty, determine whether it is a folder or a file if (file.isDirectory()){ //Enter the description here as a folder. At this time, you need to get all the files under the current folder, including the directory File[] files=file.listFiles();//Note: Here you can only use listFiles(), you cannot use list() //All the contents under files, may be folders, may also be files, then you need to determine one by one whether it is a file or a folder. This determination process is the method encapsulated here.//Therefore, you can call yourself to determine, implement recursion for (File flies2:files) { filesDirs(flies2); } }else{ System.out.println("file name"+file); } }else{ System.out.println("file does not exist"); } }}
At this point, the study on "how to use File class application to traverse all files under folder in java" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.