In the project, it is sometimes necessary to get all the files or folders under the folder, as well as the corresponding last modified time. The following code implements the iteration to read the file under the specified path, and the modification time can be added to the LastModified () method by itself.
Public class Folder { Public Static void Main(string[] args) {String path="f:/111"; ReadFile (path); }/** Iterate Read all sub files or folders under folder * @param path folder paths */ Public Static void ReadFile(String Path) {File file=NewFile (path); file[] templist = File.listfiles ();//templist.length Get the number of files or folders that are contained under a folder if(templist.length>0){ for(File f:templist) {//If it is a file, print the file name directly if(F.isfile ()) {System.out.println (F.getname ()); }if(F.isdirectory ()) {System.out.println (F.getname ()); ReadFile (path+"/"+f.getname ()); } } } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
File: Iterate through the files or folders under the folder